Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,13 @@ import assemblyai as aai
|
|
3 |
from transformers import pipeline
|
4 |
import pandas as pd
|
5 |
import os
|
6 |
-
import
|
7 |
-
from firebase_admin import credentials, db
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
"project_id": "learning-5fd92",
|
13 |
-
"private_key_id": "3d926218194aee3902d5f92b2973effbbf27b4f8",
|
14 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCiZPrNvBtVqjM1\na+/MzyZ86s/Z7fHguR1FIuNM65nxZcG6tiOgFUD5RVq9RJKpHb1eB5NTCaLVVDGg\n1nmjX45Zt/3Wj6FQKFv20iruElaNpRfhhvxCjxb37XtgwAI4BwCi8nwCi3hjuPbN\ni2jd4cCQw0lR+bPDUq/1RF/rZC5OBCmV3KpM1XuZNfpB/0UQmOdhlenba9SYhkoG\nPom/ttJBcS2nfddCvPc4qRm/z97WV+FlBtU9P4ySGSbuU+SObKhBLVEZdD9xyHw/\nYGojIxsAj2C6pahsjD94sfPN+Pve4MnGeAWvp5An0H95inDz0ewgcQW1U9gYwKBF\nDpMsWhwFAgMBAAECggEAO0lOXwnLmOy4IUq0kzsVPAmltFQwN/CdBP6FqTFiVETo\nAzg3rVvVCqwNQofkWyVmWwu891XPQr6oF6X1ZnWeTJblbw2kwNTbLjLwRVYgjzm0\njDtxoQMISZ9DqcCvjrDPxK1uJKeyXgXK5KN+t3KRkMga3nig7jAj2RELS66ZURWT\nC5ul8I1wZtRwIerussw038xkmSfhPJ3OxXovt0cMULbR/TCzWOs7442TEEQ8OVop\ng/hqbJyALiN0Je4Ba8v7Vpf2CMa+m/0XeCvwevsziKrjzsfSl5D2J7uaeaSH3YCt\nfNsKCl4kVI6p1nPCmb7/607jBiHULdumGGnZrguMSQKBgQDPQDattsZoXugsa2kN\nrx1Y+gSdR7O5CWDk41zc7YRBOlV+yZVU0Ql+NStYSUhoZNGcAtvoOE/T1b53CmWf\n2u8R9MOi1+/bha6lWjD9UhFzSC9If6ks8/GLlrQRBLcBtL8D65eR0VNr8jYh4Prj\nnWlvQNlEBnrVQiWAMP3HL+OoIwKBgQDIl7NdtyuXFmMLFEp/vBlbux5LgwtC3UkC\nlCNLRHC26Dd+ofYdH1msK8U+hbVxzeE68G5Z0uUZXkPvwKRBTP6G+G2Rkq0pn2iz\noxbPEo3k4YAU387Hs7bIE4ijBjavAoQXlX6a+KtWD/NyXNxoPITuWcY1/69oUTRY\nSzDaHGCZtwKBgQCp50usJ94KLFwMJlYuWLQngHgN9H07IZwkqNw1ZiZ5TvhOA7Z/\nnQs6Qx5wt0s8AgLw8ksT2i5fTKhjcMuVPGengdBsjLhfb/2YIxNsaT5TEwdoWPf5\nGVeZBwhBt2rMZEAAV8CfU0sfgKauKYGk3iRUh4ZWRTWn5R1XNVKnW/Q3nwKBgHj5\nJC9MnHlOAwVXg2Ztpk1wF+EqcswscC+h73chG2jzuyQfwTHnCkmPTDFcqgSsST0m\naya4zXnzI72fzG+lY4s6n7m/X7dOb/KGVOclJXX3mSr9ntNJSt53CVxoDuqU9dzT\nR7tmZM5OaF98KWCjvveQJL3EKaEb+BmXnyqrGocZAoGBAIMZviUGb7KlmuctERej\ntVSpE7WZLbXLykMFNsgiswsGXANmv8VvBguRLS0C5wCp3Xd0Erz9jld0erPNGiaf\n/8rRN2ibnMhV0BKjRNQHLFKfA24Wm2vHX7scB0Vj9fGpzQlW2UOV66m/zfX5DWua\n7X1bfrWIpyN5dv/oXkMXBnvF\n-----END PRIVATE KEY-----\n",
|
15 |
-
"client_email": "firebase-adminsdk-twa5w@learning-5fd92.iam.gserviceaccount.com",
|
16 |
-
"client_id": "116952036581323046961",
|
17 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
18 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
19 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
20 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-twa5w%40learning-5fd92.iam.gserviceaccount.com",
|
21 |
-
"universe_domain": "googleapis.com"
|
22 |
-
}
|
23 |
|
24 |
-
#
|
25 |
-
cred = credentials.Certificate(firebase_credentials)
|
26 |
-
firebase_admin.initialize_app(cred, {
|
27 |
-
'databaseURL': 'https://learning-5fd92-default-rtdb.asia-southeast1.firebasedatabase.app/'
|
28 |
-
})
|
29 |
-
ref = db.reference("/")
|
30 |
-
|
31 |
-
# Initialize AssemblyAI
|
32 |
aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
|
33 |
|
34 |
# Initialize question answering pipeline
|
@@ -52,7 +33,7 @@ questions = [
|
|
52 |
"Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
|
53 |
"Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
|
54 |
"Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
|
55 |
-
"Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing",
|
56 |
"Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
|
57 |
"Are there any other findings you would like to note?",
|
58 |
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
@@ -90,17 +71,15 @@ def generate_answer(question, context):
|
|
90 |
return result['answer']
|
91 |
|
92 |
# Function to handle audio recording and transcription
|
93 |
-
def transcribe_audio(
|
94 |
-
print(f"Received audio file at: {audio_path}")
|
95 |
-
|
96 |
-
# Check if the file exists and is not empty
|
97 |
-
if not os.path.exists(audio_path):
|
98 |
-
return "Error: Audio file does not exist."
|
99 |
-
|
100 |
-
if os.path.getsize(audio_path) == 0:
|
101 |
-
return "Error: Audio file is empty."
|
102 |
-
|
103 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
# Transcribe the audio file using AssemblyAI
|
105 |
transcriber = aai.Transcriber()
|
106 |
print("Starting transcription...")
|
@@ -131,12 +110,16 @@ def fill_dataframe(context):
|
|
131 |
|
132 |
# Function to push data to Firebase
|
133 |
def push_to_firebase(data):
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Main Gradio app function
|
138 |
-
def main(
|
139 |
-
context = transcribe_audio(
|
140 |
|
141 |
if "Error" in context:
|
142 |
return context
|
@@ -163,12 +146,12 @@ def main(audio):
|
|
163 |
submit_button.click(fn=submit_data)
|
164 |
|
165 |
return gr.Interface(
|
166 |
-
[audio],
|
167 |
[output_html, submit_button],
|
168 |
title="Audio Transcription and Question Answering App",
|
169 |
live=False
|
170 |
)
|
171 |
|
172 |
# Launch the app
|
173 |
-
main_app = main(
|
174 |
main_app.launch()
|
|
|
3 |
from transformers import pipeline
|
4 |
import pandas as pd
|
5 |
import os
|
6 |
+
from firebase_admin import credentials, db, initialize_app
|
|
|
7 |
|
8 |
+
# Initialize Firebase with your credentials
|
9 |
+
cred = credentials.Certificate('credentials.json')
|
10 |
+
initialize_app(cred, {'databaseURL': 'https://learning-5fd92-default-rtdb.asia-southeast1.firebasedatabase.app/'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Replace with your AssemblyAI API key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
|
14 |
|
15 |
# Initialize question answering pipeline
|
|
|
33 |
"Please mention if tooth decay is present with tooth number(s), else just say the word 'none' and nothing else",
|
34 |
"Have any teeth been fractured? If yes, please mention the tooth number(s), else just say 'none' and nothing else",
|
35 |
"Is there any pre-shedding mobility of teeth? If yes, please specify, else just say 'none' and nothing else",
|
36 |
+
"Does the child have malocclusion? If yes, please provide details, else just say the word 'none' and nothing else",
|
37 |
"Does the child experience pain, swelling, or abscess? If yes, please provide details, else just say 'none' and nothing else",
|
38 |
"Are there any other findings you would like to note?",
|
39 |
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
|
|
71 |
return result['answer']
|
72 |
|
73 |
# Function to handle audio recording and transcription
|
74 |
+
def transcribe_audio(audio_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
try:
|
76 |
+
# Save audio data to a temporary file
|
77 |
+
audio_path = '/tmp/audio.wav'
|
78 |
+
with open(audio_path, 'wb') as f:
|
79 |
+
f.write(audio_data)
|
80 |
+
|
81 |
+
print(f"Saved audio file at: {audio_path}")
|
82 |
+
|
83 |
# Transcribe the audio file using AssemblyAI
|
84 |
transcriber = aai.Transcriber()
|
85 |
print("Starting transcription...")
|
|
|
110 |
|
111 |
# Function to push data to Firebase
|
112 |
def push_to_firebase(data):
|
113 |
+
try:
|
114 |
+
ref = db.reference("/")
|
115 |
+
ref.push(data)
|
116 |
+
print("Data pushed to Firebase successfully.")
|
117 |
+
except Exception as e:
|
118 |
+
print(f"Error pushing data to Firebase: {e}")
|
119 |
|
120 |
# Main Gradio app function
|
121 |
+
def main(audio_data):
|
122 |
+
context = transcribe_audio(audio_data)
|
123 |
|
124 |
if "Error" in context:
|
125 |
return context
|
|
|
146 |
submit_button.click(fn=submit_data)
|
147 |
|
148 |
return gr.Interface(
|
149 |
+
[gr.Audio(type="bytes", label="Record your audio")],
|
150 |
[output_html, submit_button],
|
151 |
title="Audio Transcription and Question Answering App",
|
152 |
live=False
|
153 |
)
|
154 |
|
155 |
# Launch the app
|
156 |
+
main_app = main()
|
157 |
main_app.launch()
|