Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import assemblyai as aai
|
|
3 |
from transformers import pipeline
|
4 |
import pandas as pd
|
5 |
import os
|
6 |
-
from bs4 import BeautifulSoup
|
7 |
|
8 |
# Replace with your AssemblyAI API key
|
9 |
aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
|
@@ -97,13 +96,13 @@ def transcribe_audio(audio_path):
|
|
97 |
print(f"Exception occurred: {e}")
|
98 |
return str(e)
|
99 |
|
100 |
-
# Function to fill in the
|
101 |
-
def
|
102 |
-
|
103 |
for question in questions:
|
104 |
answer = generate_answer(question, context)
|
105 |
-
|
106 |
-
return
|
107 |
|
108 |
# Main Gradio app function
|
109 |
def main(audio):
|
@@ -112,36 +111,16 @@ def main(audio):
|
|
112 |
if "Error" in context:
|
113 |
return context
|
114 |
|
115 |
-
|
|
|
|
|
116 |
|
117 |
-
|
118 |
-
df = pd.concat([pd.DataFrame({"Question": ["Doctor’s Name", "Child’s Name"], "Answer": ["Dr. Charles Xavier", ""]}), df])
|
119 |
-
|
120 |
-
# Add a title to the DataFrame
|
121 |
-
df['Question'] = oral_health_assessment_form
|
122 |
-
|
123 |
-
# Convert DataFrame to HTML table with editable text boxes
|
124 |
-
table_html = df.to_html(index=False, escape=False, formatters={"Answer": lambda x: f'<input type="text" value="{x}" />'})
|
125 |
-
|
126 |
-
return table_html
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
tabledata = {}
|
133 |
-
|
134 |
-
# Iterate through the rows of the table
|
135 |
-
rows = soup.find_all('tr')
|
136 |
-
for row in rows:
|
137 |
-
cells = row.find_all('td')
|
138 |
-
if len(cells) == 2:
|
139 |
-
question = cells[0].text.strip()
|
140 |
-
answer = cells[1].find('input')['value']
|
141 |
-
tabledata[question] = answer
|
142 |
-
|
143 |
-
print("Submitted Table Data: ", tabledata)
|
144 |
-
return f"Data submitted successfully! {tabledata}"
|
145 |
|
146 |
# Create the Gradio interface
|
147 |
with gr.Blocks() as demo:
|
@@ -150,12 +129,14 @@ with gr.Blocks() as demo:
|
|
150 |
with gr.Column():
|
151 |
audio_input = gr.Audio(type="filepath", label="Record your audio")
|
152 |
output_html = gr.HTML(label="Assessment Form")
|
153 |
-
with gr.Column():
|
154 |
transcribe_button = gr.Button("Transcribe and Generate Form")
|
|
|
|
|
|
|
155 |
submit_button = gr.Button("Submit")
|
156 |
-
|
157 |
-
transcribe_button.click(fn=main, inputs=audio_input, outputs=
|
158 |
-
submit_button.click(fn=
|
159 |
|
160 |
# Launch the app
|
161 |
demo.launch()
|
|
|
3 |
from transformers import pipeline
|
4 |
import pandas as pd
|
5 |
import os
|
|
|
6 |
|
7 |
# Replace with your AssemblyAI API key
|
8 |
aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
|
|
|
96 |
print(f"Exception occurred: {e}")
|
97 |
return str(e)
|
98 |
|
99 |
+
# Function to fill in the answers for the text boxes
|
100 |
+
def fill_textboxes(context):
|
101 |
+
answers = []
|
102 |
for question in questions:
|
103 |
answer = generate_answer(question, context)
|
104 |
+
answers.append(answer)
|
105 |
+
return answers
|
106 |
|
107 |
# Main Gradio app function
|
108 |
def main(audio):
|
|
|
111 |
if "Error" in context:
|
112 |
return context
|
113 |
|
114 |
+
answers = fill_textboxes(context)
|
115 |
+
answers.insert(0, "") # for "Child's Name"
|
116 |
+
answers.insert(0, "Dr. Charles Xavier") # for "Doctor’s Name"
|
117 |
|
118 |
+
return answers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
def save_answers(*args):
|
121 |
+
answers_dict = {oral_health_assessment_form[i]: args[i] for i in range(len(oral_health_assessment_form))}
|
122 |
+
print("Saved answers:", answers_dict)
|
123 |
+
return "Answers saved successfully."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# Create the Gradio interface
|
126 |
with gr.Blocks() as demo:
|
|
|
129 |
with gr.Column():
|
130 |
audio_input = gr.Audio(type="filepath", label="Record your audio")
|
131 |
output_html = gr.HTML(label="Assessment Form")
|
|
|
132 |
transcribe_button = gr.Button("Transcribe and Generate Form")
|
133 |
+
|
134 |
+
with gr.Column():
|
135 |
+
textboxes = [gr.Textbox(label=question, value="", interactive=True) for question in oral_health_assessment_form]
|
136 |
submit_button = gr.Button("Submit")
|
137 |
+
|
138 |
+
transcribe_button.click(fn=main, inputs=audio_input, outputs=textboxes)
|
139 |
+
submit_button.click(fn=save_answers, inputs=textboxes, outputs=output_html)
|
140 |
|
141 |
# Launch the app
|
142 |
demo.launch()
|