Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load the generation model
|
6 |
+
generator = pipeline("text2text-generation", model="t5-small")
|
7 |
+
|
8 |
+
# Define the questions
|
9 |
+
questions = [
|
10 |
+
"Which grade is the child studying?",
|
11 |
+
"How old is the child?",
|
12 |
+
"What is the gender?",
|
13 |
+
"Can you provide the name and location of the child's school?",
|
14 |
+
"What are the names of the child's guardians or parents?",
|
15 |
+
"What is the chief complaint regarding the child's oral health? If there is none, just say the word 'none', else elaborate only on medication history",
|
16 |
+
"Can you provide any relevant medical history for the child? If there is none, just say the word 'none', else elaborate",
|
17 |
+
"Does the child take any medications regularly? If there is none, just say the word 'none'. If yes, please specify.",
|
18 |
+
"When was the child's previous dental visit? If no visits before, just say the word 'first' or mention the visit number and nothing else",
|
19 |
+
"Does the child have any habits such as thumb sucking, tongue thrusting, nail biting, or lip biting? If yes, just list them and don't provide any further details",
|
20 |
+
"Does the patient brush their teeth? Just use the words 'once daily', 'twice daily', or 'thrice daily' to answer, nothing else",
|
21 |
+
"Does the child experience bleeding gums? Just say 'yes' or 'no' for this and nothing else",
|
22 |
+
"Has the child experienced early childhood caries? Just say 'yes' or 'no' and nothing else",
|
23 |
+
"Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
|
24 |
+
"Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
|
25 |
+
"Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
|
26 |
+
"Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing else",
|
27 |
+
"Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
|
28 |
+
"Are there any other findings you would like to note?",
|
29 |
+
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
30 |
+
]
|
31 |
+
|
32 |
+
# Function to generate answers from context
|
33 |
+
def generate_answers(context):
|
34 |
+
start_time = time.time()
|
35 |
+
answers = []
|
36 |
+
for question in questions:
|
37 |
+
# Generate the answer using the model
|
38 |
+
answer = generator(f"Context: {context}\nQuestion: {question}", max_length=50)[0]['generated_text']
|
39 |
+
answers.append(answer)
|
40 |
+
end_time = time.time()
|
41 |
+
generation_time = end_time - start_time
|
42 |
+
print(f"Time taken to generate answers: {generation_time:.2f} seconds")
|
43 |
+
return answers
|
44 |
+
|
45 |
+
# Gradio interface
|
46 |
+
def main(context):
|
47 |
+
answers = generate_answers(context)
|
48 |
+
return answers
|
49 |
+
|
50 |
+
# Gradio app layout
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
context = gr.Textbox(lines=5, placeholder="Enter the context here", label="Context")
|
53 |
+
generate_button = gr.Button("Generate Answers")
|
54 |
+
output_table = gr.Dataframe(headers=["Question", "Answer"], row_count=20, col_count=2, visible=False)
|
55 |
+
save_button = gr.Button("Save Answers", visible=False)
|
56 |
+
|
57 |
+
def generate_and_show_table(context):
|
58 |
+
answers = main(context)
|
59 |
+
data = [[question, answer] for question, answer in zip(questions, answers)]
|
60 |
+
generate_button.update(interactive=False)
|
61 |
+
output_table.update(data, visible=True)
|
62 |
+
save_button.update(visible=True)
|
63 |
+
return data
|
64 |
+
|
65 |
+
generate_button.click(generate_and_show_table, inputs=context, outputs=[output_table])
|
66 |
+
save_button.click(lambda: "Answers displayed in the table", inputs=None, outputs=gr.Textbox(label="Status"))
|
67 |
+
|
68 |
+
# Launch the app
|
69 |
+
demo.launch()
|