Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def add_entry(context, question, answer, answer_start, entry_id):
|
|
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 |
file_path = "squad_dataset.json"
|
32 |
with open(file_path, "w", encoding='utf-8') as f:
|
@@ -36,17 +36,20 @@ def save_to_json():
|
|
36 |
# Interface Gradio
|
37 |
with gr.Blocks() as demo:
|
38 |
with gr.Row():
|
|
|
39 |
context = gr.Textbox(lines=5, label="Context")
|
40 |
question = gr.Textbox(lines=2, label="Question")
|
41 |
answer = gr.Textbox(lines=2, label="Answer")
|
42 |
answer_start = gr.Number(label="Answer Start")
|
43 |
entry_id = gr.Textbox(label="ID")
|
44 |
add_button = gr.Button("Add Entry")
|
45 |
-
|
|
|
|
|
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, entry_id], outputs=output)
|
50 |
-
save_button.click(fn=save_to_json, outputs=download_link)
|
51 |
|
52 |
demo.launch()
|
|
|
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(file_name):
|
30 |
global data
|
31 |
file_path = "squad_dataset.json"
|
32 |
with open(file_path, "w", encoding='utf-8') as f:
|
|
|
36 |
# Interface Gradio
|
37 |
with gr.Blocks() as demo:
|
38 |
with gr.Row():
|
39 |
+
title = gr.Textbox(label="Title")
|
40 |
context = gr.Textbox(lines=5, label="Context")
|
41 |
question = gr.Textbox(lines=2, label="Question")
|
42 |
answer = gr.Textbox(lines=2, label="Answer")
|
43 |
answer_start = gr.Number(label="Answer Start")
|
44 |
entry_id = gr.Textbox(label="ID")
|
45 |
add_button = gr.Button("Add Entry")
|
46 |
+
with gr.Row():
|
47 |
+
file_name = gr.Textbox(label="File Name", value="squad_dataset")
|
48 |
+
save_button = gr.Button("Save to JSON")
|
49 |
output = gr.Textbox(label="Output")
|
50 |
download_link = gr.File(label="Download JSON", interactive=False)
|
51 |
|
52 |
+
add_button.click(fn=add_entry, inputs=[title, context, question, answer, answer_start, entry_id], outputs=output)
|
53 |
+
save_button.click(fn=save_to_json, inputs=file_name, outputs=download_link)
|
54 |
|
55 |
demo.launch()
|