Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,15 @@ flan_t5_tokenizer = T5Tokenizer.from_pretrained(flan_t5_model_id)
|
|
34 |
flan_t5_model = T5ForConditionalGeneration.from_pretrained(flan_t5_model_id)
|
35 |
|
36 |
# Function to transcribe audio files
|
37 |
-
def transcribe_audio(
|
38 |
-
result = whisper_pipe(
|
39 |
return result['text']
|
40 |
|
41 |
# Function to extract text and questions from PDF
|
42 |
-
def extract_text_from_pdf(
|
43 |
text = ""
|
44 |
questions = []
|
45 |
-
with pdfplumber.open(
|
46 |
for page in pdf.pages:
|
47 |
page_text = page.extract_text()
|
48 |
if page_text:
|
@@ -98,17 +98,12 @@ def save_responses_to_pdf(responses, output_pdf_path):
|
|
98 |
)
|
99 |
|
100 |
content = []
|
101 |
-
# Add heading
|
102 |
-
heading = Paragraph("<b>FillUp by Umar Majeed</b>", styles['Title'])
|
103 |
-
content.append(heading)
|
104 |
-
content.append(Spacer(1, 12))
|
105 |
-
|
106 |
for index, response in enumerate(responses, start=1):
|
107 |
# Add the response number and content
|
108 |
-
|
109 |
response_text = Paragraph(response.replace("\n", "<br/>"), response_style)
|
110 |
|
111 |
-
content.append(
|
112 |
content.append(Spacer(1, 6)) # Space between heading and response
|
113 |
content.append(response_text)
|
114 |
content.append(Spacer(1, 18)) # Space between responses
|
@@ -131,18 +126,26 @@ def process_files(audio_files, pdf_file):
|
|
131 |
output_pdf_path = "output.pdf"
|
132 |
save_responses_to_pdf(responses, output_pdf_path)
|
133 |
|
134 |
-
|
|
|
135 |
|
136 |
# Gradio interface definition
|
137 |
interface = gr.Interface(
|
138 |
fn=process_files,
|
139 |
inputs=[
|
140 |
-
gr.Files(label="Upload Audio
|
141 |
-
gr.File(label="Upload PDF File
|
|
|
|
|
|
|
|
|
142 |
],
|
143 |
-
outputs=gr.File(label="Download Output PDF"),
|
144 |
title="FillUp by Umar Majeed",
|
145 |
-
description="
|
|
|
|
|
|
|
|
|
146 |
)
|
147 |
|
148 |
# Launch the interface
|
|
|
34 |
flan_t5_model = T5ForConditionalGeneration.from_pretrained(flan_t5_model_id)
|
35 |
|
36 |
# Function to transcribe audio files
|
37 |
+
def transcribe_audio(file):
|
38 |
+
result = whisper_pipe(file)
|
39 |
return result['text']
|
40 |
|
41 |
# Function to extract text and questions from PDF
|
42 |
+
def extract_text_from_pdf(pdf_file):
|
43 |
text = ""
|
44 |
questions = []
|
45 |
+
with pdfplumber.open(pdf_file) as pdf:
|
46 |
for page in pdf.pages:
|
47 |
page_text = page.extract_text()
|
48 |
if page_text:
|
|
|
98 |
)
|
99 |
|
100 |
content = []
|
|
|
|
|
|
|
|
|
|
|
101 |
for index, response in enumerate(responses, start=1):
|
102 |
# Add the response number and content
|
103 |
+
heading = Paragraph(f"<b>File {index}:</b>", styles['Heading2'])
|
104 |
response_text = Paragraph(response.replace("\n", "<br/>"), response_style)
|
105 |
|
106 |
+
content.append(heading)
|
107 |
content.append(Spacer(1, 6)) # Space between heading and response
|
108 |
content.append(response_text)
|
109 |
content.append(Spacer(1, 18)) # Space between responses
|
|
|
126 |
output_pdf_path = "output.pdf"
|
127 |
save_responses_to_pdf(responses, output_pdf_path)
|
128 |
|
129 |
+
# Return the PDF path and the generated responses
|
130 |
+
return output_pdf_path, "\n\n".join(responses)
|
131 |
|
132 |
# Gradio interface definition
|
133 |
interface = gr.Interface(
|
134 |
fn=process_files,
|
135 |
inputs=[
|
136 |
+
gr.Files(label="Upload Audio Dataset"),
|
137 |
+
gr.File(label="Upload PDF File with Questions")
|
138 |
+
],
|
139 |
+
outputs=[
|
140 |
+
gr.File(label="Download Output PDF"),
|
141 |
+
gr.Textbox(label="Generated Responses", lines=20, placeholder="The responses will be shown here...")
|
142 |
],
|
|
|
143 |
title="FillUp by Umar Majeed",
|
144 |
+
description="""This is a beta version of FillUp, an application designed to auto-fill predefined forms using call data.
|
145 |
+
Upload the audio files from which you want to extract text and a PDF form that contains the questions to be answered.
|
146 |
+
At the end, you will receive a PDF file with the responses.
|
147 |
+
|
148 |
+
For reference, you can download a sample form from [https://drive.google.com/drive/folders/13LolIqxufzysqNoGMfuCAvpA9AkbRfL7?usp=drive_link]. Use this dummy data to understand how the model works."""
|
149 |
)
|
150 |
|
151 |
# Launch the interface
|