Pranjal12345
commited on
Commit
•
44c9e92
1
Parent(s):
a7d3de0
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
API_URL = "https://api-inference.huggingface.co/models/potsawee/t5-large-generation-squad-QuestionAnswer"
|
6 |
headers = {"Authorization": "Bearer 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"}
|
@@ -9,11 +18,13 @@ def query(payload):
|
|
9 |
response = requests.post(API_URL, headers=headers, json=payload)
|
10 |
return response.json()
|
11 |
|
12 |
-
def generate_question_answer_pairs(
|
13 |
-
if
|
14 |
-
return "Please
|
|
|
|
|
15 |
|
16 |
-
sentences = re.split(r'(?<=[.!?])',
|
17 |
outputs = []
|
18 |
|
19 |
for sentence in sentences:
|
@@ -26,12 +37,12 @@ def generate_question_answer_pairs(input_text):
|
|
26 |
return outputs
|
27 |
|
28 |
title = "Question-Answer Pairs Generation"
|
29 |
-
|
30 |
output_text = gr.Textbox()
|
31 |
|
32 |
interface = gr.Interface(
|
33 |
fn=generate_question_answer_pairs,
|
34 |
-
inputs=
|
35 |
outputs=output_text,
|
36 |
title=title,
|
37 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import re
|
4 |
+
import fitz
|
5 |
+
|
6 |
+
def extract_text_from_pdf(pdf_file_path):
|
7 |
+
doc = fitz.open(pdf_file_path)
|
8 |
+
text = ""
|
9 |
+
for page in doc:
|
10 |
+
text+=page.get_text()
|
11 |
+
|
12 |
+
return text
|
13 |
|
14 |
API_URL = "https://api-inference.huggingface.co/models/potsawee/t5-large-generation-squad-QuestionAnswer"
|
15 |
headers = {"Authorization": "Bearer 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"}
|
|
|
18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
19 |
return response.json()
|
20 |
|
21 |
+
def generate_question_answer_pairs(input_file):
|
22 |
+
if input_file is None:
|
23 |
+
return "Please upload a file"
|
24 |
+
|
25 |
+
pdf_text = extract_text_from_pdf(input_file)
|
26 |
|
27 |
+
sentences = re.split(r'(?<=[.!?])', pdf_text)
|
28 |
outputs = []
|
29 |
|
30 |
for sentence in sentences:
|
|
|
37 |
return outputs
|
38 |
|
39 |
title = "Question-Answer Pairs Generation"
|
40 |
+
input_file = gr.File(label="Upload a PDF file")
|
41 |
output_text = gr.Textbox()
|
42 |
|
43 |
interface = gr.Interface(
|
44 |
fn=generate_question_answer_pairs,
|
45 |
+
inputs=input_file,
|
46 |
outputs=output_text,
|
47 |
title=title,
|
48 |
)
|