Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
-
import os
|
4 |
|
5 |
# Lista para armazenar os dados
|
6 |
data = []
|
7 |
|
8 |
# Função para adicionar contextos, perguntas e respostas
|
9 |
-
def add_entry(context, question, answer, answer_start):
|
10 |
global data
|
11 |
entry = {
|
|
|
12 |
"context": context,
|
13 |
-
"
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
"answer_start": answer_start
|
20 |
-
}
|
21 |
-
]
|
22 |
-
}
|
23 |
-
]
|
24 |
}
|
25 |
data.append(entry)
|
26 |
return "Entry added!"
|
@@ -28,25 +23,26 @@ def add_entry(context, question, answer, answer_start):
|
|
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(
|
35 |
return file_path
|
36 |
|
37 |
# Interface Gradio
|
38 |
with gr.Blocks() as demo:
|
39 |
with gr.Row():
|
|
|
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 |
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()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
|
|
3 |
|
4 |
# Lista para armazenar os dados
|
5 |
data = []
|
6 |
|
7 |
# Função para adicionar contextos, perguntas e respostas
|
8 |
+
def add_entry(title, context, question, answer, answer_start, entry_id):
|
9 |
global data
|
10 |
entry = {
|
11 |
+
"title": title,
|
12 |
"context": context,
|
13 |
+
"question": question,
|
14 |
+
"id": entry_id,
|
15 |
+
"answers": {
|
16 |
+
"answer_start": [answer_start],
|
17 |
+
"text": [answer]
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
data.append(entry)
|
21 |
return "Entry added!"
|
|
|
23 |
# Função para salvar os dados em um arquivo JSON e retornar o caminho do arquivo
|
24 |
def save_to_json():
|
25 |
global data
|
|
|
26 |
file_path = "squad_dataset.json"
|
27 |
with open(file_path, "w", encoding='utf-8') as f:
|
28 |
+
json.dump(data, f, ensure_ascii=False, indent=4)
|
29 |
return file_path
|
30 |
|
31 |
# Interface Gradio
|
32 |
with gr.Blocks() as demo:
|
33 |
with gr.Row():
|
34 |
+
title = gr.Textbox(label="Title")
|
35 |
context = gr.Textbox(lines=5, label="Context")
|
36 |
question = gr.Textbox(lines=2, label="Question")
|
37 |
answer = gr.Textbox(lines=2, label="Answer")
|
38 |
answer_start = gr.Number(label="Answer Start")
|
39 |
+
entry_id = gr.Textbox(label="ID")
|
40 |
add_button = gr.Button("Add Entry")
|
41 |
save_button = gr.Button("Save to JSON")
|
42 |
output = gr.Textbox(label="Output")
|
43 |
download_link = gr.File(label="Download JSON", interactive=False)
|
44 |
|
45 |
+
add_button.click(fn=add_entry, inputs=[title, context, question, answer, answer_start, entry_id], outputs=output)
|
46 |
save_button.click(fn=save_to_json, outputs=download_link)
|
47 |
|
48 |
demo.launch()
|