NikilDGr8 commited on
Commit
8593387
1 Parent(s): 0418f53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -77
app.py CHANGED
@@ -1,78 +1,37 @@
1
  import gradio as gr
2
- from transformers import pipeline, set_seed
3
-
4
- # Define the questions
5
- questions = [
6
- "Which grade is the child studying?",
7
- "How old is the child?",
8
- "What is the gender?",
9
- "Can you provide the name and location of the child's school?",
10
- "What are the names of the child's guardians or parents?",
11
- "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",
12
- "Can you provide any relevant medical history for the child? If there is none, just say the word 'none', else elaborate",
13
- "Does the child take any medications regularly? If there is none, just say the word 'none'. If yes, please specify.",
14
- "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",
15
- "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",
16
- "Does the patient brush their teeth? Just use the words 'once daily', 'twice daily', or 'thrice daily' to answer, nothing else",
17
- "Does the child experience bleeding gums? Just say 'yes' or 'no' for this and nothing else",
18
- "Has the child experienced early childhood caries? Just say 'yes' or 'no' and nothing else",
19
- "Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
20
- "Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
21
- "Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
22
- "Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing else",
23
- "Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
24
- "Are there any other findings you would like to note?",
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.Interface(
63
- fn=form_submit,
64
- inputs=gr.inputs.Textbox(lines=20, label="Context", default=default_context),
65
- outputs=gr.outputs.Textbox(label="Generated Answers", type="text"),
66
- title="Dental Health Record Form with GPT-2",
67
- description="Fill out the context and click submit to generate answers to the questions.",
68
- examples=[default_context],
69
- allow_flagging=False
70
- )
71
-
72
- # Function to submit the form
73
- def form_submit(context):
74
- generated_answers = generate_answers(context)
75
- return generated_answers
76
-
77
- # Launch the interface
78
- form_display().launch()
 
1
  import gradio as gr
2
+ import assemblyai as aai
3
+ import os
4
+
5
+ # Replace with your AssemblyAI API key
6
+ aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
7
+
8
+ # Function to handle audio recording and transcription
9
+ def transcribe_audio(audio):
10
+ # Save the recorded audio to a file
11
+ audio_path = "recorded_audio.wav"
12
+ audio.save(audio_path)
13
+
14
+ # Transcribe the audio file using AssemblyAI
15
+ transcriber = aai.Transcriber()
16
+ transcript = transcriber.transcribe(audio_path)
17
+
18
+ # Handle the transcription result
19
+ if transcript.status == aai.TranscriptStatus.error:
20
+ return transcript.error
21
+ else:
22
+ return transcript.text
23
+
24
+ # Create the Gradio interface
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# Audio Transcription App")
27
+ with gr.Row():
28
+ with gr.Column():
29
+ audio_input = gr.Audio(source="microphone", type="file", label="Record your audio")
30
+ output_text = gr.Textbox(label="Transcription")
31
+ with gr.Column():
32
+ transcribe_button = gr.Button("Transcribe")
33
+
34
+ transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=output_text)
35
+
36
+ # Launch the app
37
+ demo.launch()