Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -142,13 +142,13 @@ def save_answers(*args):
|
|
142 |
# Function to download table as CSV
|
143 |
def download_table_to_csv():
|
144 |
# Fetch data from Supabase table
|
145 |
-
response = supabase.table(
|
146 |
|
147 |
# Check if data is available
|
148 |
if not response.data:
|
149 |
print("No data found in the table.")
|
150 |
-
return
|
151 |
-
|
152 |
data = response.data
|
153 |
|
154 |
# Prepare CSV data
|
@@ -162,21 +162,26 @@ def download_table_to_csv():
|
|
162 |
for row in data:
|
163 |
csv_data.append(row.values())
|
164 |
|
165 |
-
# Save CSV data to file
|
166 |
-
|
167 |
-
with open(
|
168 |
writer = csv.writer(f)
|
169 |
writer.writerows(csv_data)
|
170 |
|
171 |
-
print(f"Downloaded table '
|
172 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
# Create the Gradio interface
|
175 |
with gr.Blocks() as demo:
|
176 |
gr.Markdown("# OHA Form Filler App")
|
177 |
audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
|
178 |
transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
|
179 |
-
download_button = gr.Button("Download as CSV", elem_id="download_button")
|
180 |
|
181 |
with gr.Row(elem_id="textboxes_row"):
|
182 |
with gr.Column():
|
@@ -189,7 +194,11 @@ with gr.Blocks() as demo:
|
|
189 |
|
190 |
transcribe_button.click(fn=main, inputs=audio_input, outputs=textboxes_left + textboxes_right)
|
191 |
submit_button.click(fn=save_answers, inputs=textboxes_left + textboxes_right, outputs=output_html)
|
192 |
-
|
|
|
|
|
|
|
|
|
193 |
|
194 |
# Launch the app
|
195 |
demo.launch(share=True)
|
|
|
142 |
# Function to download table as CSV
|
143 |
def download_table_to_csv():
|
144 |
# Fetch data from Supabase table
|
145 |
+
response = supabase.table(table_name).select("*").execute()
|
146 |
|
147 |
# Check if data is available
|
148 |
if not response.data:
|
149 |
print("No data found in the table.")
|
150 |
+
return None
|
151 |
+
|
152 |
data = response.data
|
153 |
|
154 |
# Prepare CSV data
|
|
|
162 |
for row in data:
|
163 |
csv_data.append(row.values())
|
164 |
|
165 |
+
# Save CSV data to file (replace 'your_table.csv' with desired filename)
|
166 |
+
csv_file = "your_table.csv"
|
167 |
+
with open(csv_file, "w", newline='') as f:
|
168 |
writer = csv.writer(f)
|
169 |
writer.writerows(csv_data)
|
170 |
|
171 |
+
print(f"Downloaded table '{table_name}' to '{csv_file}'")
|
172 |
+
return csv_file
|
173 |
+
|
174 |
+
def gradio_download():
|
175 |
+
file_path = download_table_to_csv()
|
176 |
+
if file_path:
|
177 |
+
return file_path
|
178 |
+
return None
|
179 |
|
180 |
# Create the Gradio interface
|
181 |
with gr.Blocks() as demo:
|
182 |
gr.Markdown("# OHA Form Filler App")
|
183 |
audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
|
184 |
transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
|
|
|
185 |
|
186 |
with gr.Row(elem_id="textboxes_row"):
|
187 |
with gr.Column():
|
|
|
194 |
|
195 |
transcribe_button.click(fn=main, inputs=audio_input, outputs=textboxes_left + textboxes_right)
|
196 |
submit_button.click(fn=save_answers, inputs=textboxes_left + textboxes_right, outputs=output_html)
|
197 |
+
|
198 |
+
download_button = gr.Button("Download Table as CSV")
|
199 |
+
download_csv_output = gr.File(label="Download CSV")
|
200 |
+
|
201 |
+
download_button.click(fn=gradio_download, inputs=[], outputs=download_csv_output)
|
202 |
|
203 |
# Launch the app
|
204 |
demo.launch(share=True)
|