Dental_LLM / app.py
NikilDGr8's picture
Update app.py
553ea41 verified
raw
history blame
No virus
4.77 kB
import gradio as gr
from transformers import pipeline, set_seed
# Define the questions
questions = [
"Which grade is the child studying?",
"How old is the child?",
"What is the gender?",
"Can you provide the name and location of the child's school?",
"What are the names of the child's guardians or parents?",
"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",
"Can you provide any relevant medical history for the child? If there is none, just say the word 'none', else elaborate",
"Does the child take any medications regularly? If there is none, just say the word 'none'. If yes, please specify.",
"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",
"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",
"Does the patient brush their teeth? Just use the words 'once daily', 'twice daily', or 'thrice daily' to answer, nothing else",
"Does the child experience bleeding gums? Just say 'yes' or 'no' for this and nothing else",
"Has the child experienced early childhood caries? Just say 'yes' or 'no' and nothing else",
"Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
"Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
"Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
"Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing else",
"Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
"Are there any other findings you would like to note?",
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
]
# Initialize answers
answers = {q: '' for q in questions}
# Define the default context
default_context = (
"My child, Sarah, is studying in the 3rd grade. She is 8 years old and is a girl. "
"Sarah attends Greenwood Elementary School, located in Springfield. "
"Her guardians are myself, Emma Johnson, and her father, Michael Johnson.\n\n"
"Sarah's chief complaint regarding her oral health is that she has been experiencing some discomfort due to a cavity in her molar. "
"Other than that, she has no significant medication history. She has no relevant medical history to report. "
"Sarah does not take any medications regularly.\n\n"
"Her last dental visit was about a year ago, so this is her second visit. "
"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"
"Sarah brushes her teeth twice daily. She does not experience bleeding gums. "
"Sarah has not experienced early childhood caries. Unfortunately, she does have tooth decay present in tooth numbers 14 and 15. "
"None of her teeth have been fractured. There is no pre-shedding mobility of teeth to report.\n\n"
"Sarah does not have malocclusion. She does not experience any pain, swelling, or abscess at the moment. "
"There are no other significant findings to note.\n\n"
"As for the treatment plan, I would recommend a filling for the decayed teeth."
)
# Load the GPT-2 model for text generation
generator = pipeline('text-generation', model='gpt2')
# Function to generate answers
def generate_answers(context):
prompt = context + "\n\n" + "\n\n".join(questions)
set_seed(42) # Ensure reproducibility
generated_text = generator(prompt, max_length=300, num_return_sequences=1)[0]['generated_text']
generated_answers = generated_text.split("\n\n")
return generated_answers
# Function to display the form
def form_display():
return gr.Interface(
fn=form_submit,
inputs=gr.inputs.Textbox(lines=20, label="Context", default=default_context),
outputs=gr.outputs.Textbox(label="Generated Answers", type="text"),
title="Dental Health Record Form with GPT-2",
description="Fill out the context and click submit to generate answers to the questions.",
examples=[default_context],
allow_flagging=False
)
# Function to submit the form
def form_submit(context):
generated_answers = generate_answers(context)
return generated_answers
# Launch the interface
form_display().launch()