Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
|
|
3 |
|
4 |
# Lista para armazenar os dados
|
5 |
data = []
|
@@ -24,13 +25,14 @@ def add_entry(context, question, answer, answer_start):
|
|
24 |
data.append(entry)
|
25 |
return "Entry added!"
|
26 |
|
27 |
-
# Função para salvar os dados em um arquivo JSON
|
28 |
def save_to_json():
|
29 |
global data
|
30 |
squad_format = {"data": data}
|
31 |
-
|
|
|
32 |
json.dump(squad_format, f, ensure_ascii=False, indent=4)
|
33 |
-
return
|
34 |
|
35 |
# Interface Gradio
|
36 |
with gr.Blocks() as demo:
|
@@ -42,8 +44,9 @@ with gr.Blocks() as demo:
|
|
42 |
add_button = gr.Button("Add Entry")
|
43 |
save_button = gr.Button("Save to JSON")
|
44 |
output = gr.Textbox(label="Output")
|
|
|
45 |
|
46 |
add_button.click(fn=add_entry, inputs=[context, question, answer, answer_start], outputs=output)
|
47 |
-
save_button.click(fn=save_to_json, outputs=
|
48 |
|
49 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
+
import os
|
4 |
|
5 |
# Lista para armazenar os dados
|
6 |
data = []
|
|
|
25 |
data.append(entry)
|
26 |
return "Entry added!"
|
27 |
|
28 |
+
# Função para salvar os dados em um arquivo JSON e retornar o caminho do arquivo
|
29 |
def save_to_json():
|
30 |
global data
|
31 |
squad_format = {"data": data}
|
32 |
+
file_path = "squad_dataset.json"
|
33 |
+
with open(file_path, "w", encoding='utf-8') as f:
|
34 |
json.dump(squad_format, f, ensure_ascii=False, indent=4)
|
35 |
+
return file_path
|
36 |
|
37 |
# Interface Gradio
|
38 |
with gr.Blocks() as demo:
|
|
|
44 |
add_button = gr.Button("Add Entry")
|
45 |
save_button = gr.Button("Save to JSON")
|
46 |
output = gr.Textbox(label="Output")
|
47 |
+
download_link = gr.File(label="Download JSON", interactive=False)
|
48 |
|
49 |
add_button.click(fn=add_entry, inputs=[context, question, answer, answer_start], outputs=output)
|
50 |
+
save_button.click(fn=save_to_json, outputs=download_link)
|
51 |
|
52 |
demo.launch()
|