NikilDGr8 commited on
Commit
7166f82
1 Parent(s): b90c811

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -7
app.py CHANGED
@@ -1,10 +1,68 @@
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_path):
10
  print(f"Received audio file at: {audio_path}")
@@ -29,24 +87,53 @@ def transcribe_audio(audio_path):
29
  print(f"Error during transcription: {transcript.error}")
30
  return transcript.error
31
  else:
32
- print(f"Transcription text: {transcript.text}")
33
- return transcript.text
 
34
 
35
  except Exception as e:
36
  print(f"Exception occurred: {e}")
37
  return str(e)
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Create the Gradio interface
40
  with gr.Blocks() as demo:
41
- gr.Markdown("# Audio Transcription App")
42
  with gr.Row():
43
  with gr.Column():
44
  audio_input = gr.Audio(type="filepath", label="Record your audio")
45
- output_text = gr.Textbox(label="Transcription")
46
  with gr.Column():
47
- transcribe_button = gr.Button("Transcribe")
48
 
49
- transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=output_text)
50
 
51
  # Launch the app
52
  demo.launch()
 
1
  import gradio as gr
2
  import assemblyai as aai
3
+ from transformers import pipeline
4
+ import pandas as pd
5
 
6
  # Replace with your AssemblyAI API key
7
  aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
8
 
9
+ # Initialize question answering pipeline
10
+ question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
11
+
12
+ # List of questions
13
+ questions = [
14
+ "Which grade is the child studying?",
15
+ "How old is the child?",
16
+ "What is the gender?",
17
+ "Can you provide the name and location of the child's school?",
18
+ "What are the names of the child's guardians or parents?",
19
+ "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",
20
+ "Can you provide any relevant medical history for the child? If there is none, just say the word 'none', else elaborate",
21
+ "Does the child take any medications regularly? If there is none, just say the word 'none'. If yes, please specify.",
22
+ "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",
23
+ "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",
24
+ "Does the patient brush their teeth? Just use the words 'once daily', 'twice daily', or 'thrice daily' to answer, nothing else",
25
+ "Does the child experience bleeding gums? Just say 'yes' or 'no' for this and nothing else",
26
+ "Has the child experienced early childhood caries? Just say 'yes' or 'no' and nothing else",
27
+ "Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
28
+ "Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
29
+ "Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
30
+ "Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing else",
31
+ "Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
32
+ "Are there any other findings you would like to note?",
33
+ "What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
34
+ ]
35
+
36
+ oral_health_assessment_form = [
37
+ "Doctor’s Name",
38
+ "Child’s Name",
39
+ "Grade",
40
+ "Age",
41
+ "Gender",
42
+ "School name and place",
43
+ "Guardian/Parents name",
44
+ "Chief complaint",
45
+ "Medical history",
46
+ "Medication history",
47
+ "Previous dental visit",
48
+ "Habits",
49
+ "Brushing habit",
50
+ "Bleeding gums",
51
+ "Early Childhood caries",
52
+ "Decayed",
53
+ "Fractured teeth",
54
+ "Preshedding mobility",
55
+ "Malocclusion",
56
+ "Does the child have pain, swelling or abscess? (Urgent care need)",
57
+ "Any other finding",
58
+ "Treatment plan",
59
+ ]
60
+
61
+ # Function to generate answers for the questions
62
+ def generate_answer(question, context):
63
+ result = question_answerer(question=question, context=context)
64
+ return result['answer']
65
+
66
  # Function to handle audio recording and transcription
67
  def transcribe_audio(audio_path):
68
  print(f"Received audio file at: {audio_path}")
 
87
  print(f"Error during transcription: {transcript.error}")
88
  return transcript.error
89
  else:
90
+ context = transcript.text
91
+ print(f"Transcription text: {context}")
92
+ return context
93
 
94
  except Exception as e:
95
  print(f"Exception occurred: {e}")
96
  return str(e)
97
 
98
+ # Function to fill in the DataFrame with answers
99
+ def fill_dataframe(context):
100
+ data = []
101
+ for question in questions:
102
+ answer = generate_answer(question, context)
103
+ data.append({"Question": question, "Answer": answer})
104
+ return pd.DataFrame(data)
105
+
106
+ # Main Gradio app function
107
+ def main(audio):
108
+ context = transcribe_audio(audio)
109
+
110
+ if "Error" in context:
111
+ return context
112
+
113
+ df = fill_dataframe(context)
114
+
115
+ # Add doctor's and patient's name to the beginning of the DataFrame
116
+ df = pd.concat([pd.DataFrame({"Question": ["Doctor’s Name", "Child’s Name"], "Answer": ["Dr. Charles Xavier", ""]}), df])
117
+
118
+ # Add a title to the DataFrame
119
+ df['Question'] = oral_health_assessment_form
120
+
121
+ # Convert DataFrame to HTML table with editable text boxes
122
+ table_html = df.to_html(index=False, escape=False, formatters={"Answer": lambda x: f'<input type="text" value="{x}" />'})
123
+
124
+ return table_html
125
+
126
  # Create the Gradio interface
127
  with gr.Blocks() as demo:
128
+ gr.Markdown("# Audio Transcription and Question Answering App")
129
  with gr.Row():
130
  with gr.Column():
131
  audio_input = gr.Audio(type="filepath", label="Record your audio")
132
+ output_html = gr.HTML(label="Assessment Form")
133
  with gr.Column():
134
+ transcribe_button = gr.Button("Transcribe and Generate Form")
135
 
136
+ transcribe_button.click(fn=main, inputs=audio_input, outputs=output_html)
137
 
138
  # Launch the app
139
  demo.launch()