Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ import numpy as np
|
|
15 |
|
16 |
import subprocess
|
17 |
import tempfile
|
|
|
18 |
|
19 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
20 |
|
@@ -225,9 +226,10 @@ def process_image(image, task_prompt, text_input=None, model_id='microsoft/Flore
|
|
225 |
# Function to convert the output text to a downloadable text file
|
226 |
def save_text_as_file(output_text):
|
227 |
# Use a temporary file to store the output text for download
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
231 |
|
232 |
css = """
|
233 |
#output {
|
@@ -285,6 +287,6 @@ with gr.Blocks(css=css) as demo:
|
|
285 |
submit_btn.click(process_image, [input_img, task_prompt, text_input, model_selector], [output_text, output_img])
|
286 |
|
287 |
# Add functionality to generate and download text file
|
288 |
-
download_btn.
|
289 |
|
290 |
-
demo.launch(debug=True)
|
|
|
15 |
|
16 |
import subprocess
|
17 |
import tempfile
|
18 |
+
import os
|
19 |
|
20 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
21 |
|
|
|
226 |
# Function to convert the output text to a downloadable text file
|
227 |
def save_text_as_file(output_text):
|
228 |
# Use a temporary file to store the output text for download
|
229 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt")
|
230 |
+
with open(temp_file.name, "w") as f:
|
231 |
+
f.write(output_text)
|
232 |
+
return temp_file.name
|
233 |
|
234 |
css = """
|
235 |
#output {
|
|
|
287 |
submit_btn.click(process_image, [input_img, task_prompt, text_input, model_selector], [output_text, output_img])
|
288 |
|
289 |
# Add functionality to generate and download text file
|
290 |
+
download_btn.update(save_text_as_file, inputs=output_text, outputs=download_btn)
|
291 |
|
292 |
+
demo.launch(debug=True)
|