NikilDGr8 commited on
Commit
8920538
1 Parent(s): 683104e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -4,13 +4,13 @@ from transformers import pipeline
4
  import os
5
  from supabase import create_client, Client
6
  from datetime import datetime
 
7
 
8
  # Add your AssemblyAI API key as Environment Variable
9
  aai.settings.api_key = os.environ['Assembly']
10
  url: str = os.environ['DBUrl']
11
  key: str = os.environ['DBKey']
12
 
13
-
14
  # Initialize question answering pipeline
15
  question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
16
 
@@ -62,6 +62,7 @@ oral_health_assessment_form = [
62
  "Any other finding",
63
  "Treatment plan",
64
  ]
 
65
  # Function to generate answers for the questions
66
  def generate_answer(question, context):
67
  result = question_answerer(question=question, context=context)
@@ -138,13 +139,24 @@ def save_answers(*args):
138
  print(f"Error inserting data into Supabase: {e}")
139
  return f"Error saving answers: {e}"
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  # Create the Gradio interface
142
  with gr.Blocks() as demo:
143
  gr.Markdown("# OHA Form Filler App")
144
-
145
- # Add HTML box to show the status
146
- status_box = gr.HTML("<div id='status_box' style='width: 100px; height: 30px; background-color: red;'></div>")
147
-
148
  audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
149
  transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
150
 
@@ -157,16 +169,9 @@ with gr.Blocks() as demo:
157
  submit_button = gr.Button("Submit", elem_id="submit_button")
158
  output_html = gr.HTML(label="Submitted Answers")
159
 
160
- # Update status box color based on audio input
161
- def update_status(audio):
162
- if audio:
163
- status_box_value = "<div id='status_box' style='width: 100px; height: 30px; background-color: green;'></div>"
164
- else:
165
- status_box_value = "<div id='status_box' style='width: 100px; height: 30px; background-color: red;'></div>"
166
- return status_box_value, main(audio)
167
-
168
- transcribe_button.click(fn=update_status, inputs=audio_input, outputs=[status_box, textboxes_left + textboxes_right])
169
  submit_button.click(fn=save_answers, inputs=textboxes_left + textboxes_right, outputs=output_html)
 
170
 
171
  # Launch the app
172
- demo.launch(share=True)
 
4
  import os
5
  from supabase import create_client, Client
6
  from datetime import datetime
7
+ import pandas as pd
8
 
9
  # Add your AssemblyAI API key as Environment Variable
10
  aai.settings.api_key = os.environ['Assembly']
11
  url: str = os.environ['DBUrl']
12
  key: str = os.environ['DBKey']
13
 
 
14
  # Initialize question answering pipeline
15
  question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
16
 
 
62
  "Any other finding",
63
  "Treatment plan",
64
  ]
65
+
66
  # Function to generate answers for the questions
67
  def generate_answer(question, context):
68
  result = question_answerer(question=question, context=context)
 
139
  print(f"Error inserting data into Supabase: {e}")
140
  return f"Error saving answers: {e}"
141
 
142
+ def download_csv():
143
+ try:
144
+ response = supabase.table('oral_health_assessments').select("*").execute()
145
+ data = response.data
146
+ if data:
147
+ df = pd.DataFrame(data)
148
+ csv_data = df.to_csv(index=False)
149
+ return csv_data
150
+ else:
151
+ return "No data available"
152
+ except Exception as e:
153
+ print(f"Error fetching data from Supabase: {e}")
154
+ return f"Error: {e}"
155
+
156
  # Create the Gradio interface
157
  with gr.Blocks() as demo:
158
  gr.Markdown("# OHA Form Filler App")
159
+ download_button = gr.Button("Download CSV", elem_id="download_button")
 
 
 
160
  audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
161
  transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
162
 
 
169
  submit_button = gr.Button("Submit", elem_id="submit_button")
170
  output_html = gr.HTML(label="Submitted Answers")
171
 
172
+ transcribe_button.click(fn=main, inputs=audio_input, outputs=textboxes_left + textboxes_right)
 
 
 
 
 
 
 
 
173
  submit_button.click(fn=save_answers, inputs=textboxes_left + textboxes_right, outputs=output_html)
174
+ download_button.click(fn=download_csv, inputs=None, outputs=gr.File(label="Download CSV"))
175
 
176
  # Launch the app
177
+ demo.launch(share=True)