Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,5 @@
|
|
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 = [
|
@@ -29,41 +25,57 @@ questions = [
|
|
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 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
-
|
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 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
output_table.update(data, visible=True)
|
62 |
-
save_button.update(visible=True)
|
63 |
-
return data
|
64 |
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
# Launch the
|
69 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, set_seed
|
|
|
|
|
|
|
3 |
|
4 |
# Define the questions
|
5 |
questions = [
|
|
|
25 |
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
26 |
]
|
27 |
|
28 |
+
# Initialize answers
|
29 |
+
answers = {q: '' for q in questions}
|
30 |
+
|
31 |
+
# Define the default context
|
32 |
+
default_context = (
|
33 |
+
"My child, Sarah, is studying in the 3rd grade. She is 8 years old and is a girl. "
|
34 |
+
"Sarah attends Greenwood Elementary School, located in Springfield. "
|
35 |
+
"Her guardians are myself, Emma Johnson, and her father, Michael Johnson.\n\n"
|
36 |
+
"Sarah's chief complaint regarding her oral health is that she has been experiencing some discomfort due to a cavity in her molar. "
|
37 |
+
"Other than that, she has no significant medication history. She has no relevant medical history to report. "
|
38 |
+
"Sarah does not take any medications regularly.\n\n"
|
39 |
+
"Her last dental visit was about a year ago, so this is her second visit. "
|
40 |
+
"Sarah has a habit of occasionally biting her nails, but she doesn't have any other habits like thumb sucking or tongue thrusting.\n\n"
|
41 |
+
"Sarah brushes her teeth twice daily. She does not experience bleeding gums. "
|
42 |
+
"Sarah has not experienced early childhood caries. Unfortunately, she does have tooth decay present in tooth numbers 14 and 15. "
|
43 |
+
"None of her teeth have been fractured. There is no pre-shedding mobility of teeth to report.\n\n"
|
44 |
+
"Sarah does not have malocclusion. She does not experience any pain, swelling, or abscess at the moment. "
|
45 |
+
"There are no other significant findings to note.\n\n"
|
46 |
+
"As for the treatment plan, I would recommend a filling for the decayed teeth."
|
47 |
+
)
|
48 |
|
49 |
+
# Load the GPT-2 model for text generation
|
50 |
+
generator = pipeline('text-generation', model='gpt2')
|
51 |
+
|
52 |
+
# Function to generate answers
|
53 |
+
def generate_answers(context):
|
54 |
+
prompt = context + "\n\n" + "\n\n".join(questions)
|
55 |
+
set_seed(42) # Ensure reproducibility
|
56 |
+
generated_text = generator(prompt, max_length=300, num_return_sequences=1)[0]['generated_text']
|
57 |
+
generated_answers = generated_text.split("\n\n")
|
58 |
+
return generated_answers
|
59 |
|
60 |
+
# Function to display the form
|
61 |
+
def form_display():
|
62 |
+
return [gr.outputs.Textbox(label="Generated Answers", type="text")]
|
|
|
|
|
|
|
63 |
|
64 |
+
# Function to submit the form
|
65 |
+
def form_submit(context):
|
66 |
+
generated_answers = generate_answers(context)
|
67 |
+
return generated_answers
|
|
|
|
|
|
|
68 |
|
69 |
+
# Create Gradio interface
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=form_submit,
|
72 |
+
inputs=gr.inputs.Textbox(label="Context", type="text", default=default_context, lines=20),
|
73 |
+
outputs=form_display(),
|
74 |
+
title="Dental Health Record Form with GPT-2",
|
75 |
+
description="Fill out the context and click submit to generate answers to the questions.",
|
76 |
+
examples=[default_context],
|
77 |
+
allow_flagging=False
|
78 |
+
)
|
79 |
|
80 |
+
# Launch the interface
|
81 |
+
iface.launch()
|