Spaces:
Running
Running
File size: 1,792 Bytes
7032bbe d183607 7032bbe d183607 7032bbe d183607 a1c48d3 d183607 a1c48d3 d183607 422da4e 95f446b d183607 422da4e 77399c5 422da4e d183607 95f446b d183607 77399c5 d183607 95f446b d183607 422da4e d183607 95f446b 7032bbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import json
# Lista para armazenar os dados
data = []
# Função para adicionar contextos, perguntas e respostas
def add_entry(context, question, answer, answer_start, entry_id):
global data
entry = {
"context": context,
"qas":[
{
"id": entry_id,
"question": question,
"answers": [
{
"text": answer,
"answer_start": answer_start
}
]
}
]
}
data.append(entry)
return "Entry added!"
# Função para salvar os dados em um arquivo JSON e retornar o caminho do arquivo
def save_to_json(file_name):
global data
file_path = "squad_dataset.json"
with open(file_path, "w", encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
return file_path
# Interface Gradio
with gr.Blocks() as demo:
with gr.Row():
title = gr.Textbox(label="Title")
context = gr.Textbox(lines=5, label="Context")
question = gr.Textbox(lines=2, label="Question")
answer = gr.Textbox(lines=2, label="Answer")
answer_start = gr.Number(label="Answer Start")
entry_id = gr.Textbox(label="ID")
add_button = gr.Button("Add Entry")
with gr.Row():
file_name = gr.Textbox(label="File Name", value="squad_dataset")
save_button = gr.Button("Save to JSON")
output = gr.Textbox(label="Output")
download_link = gr.File(label="Download JSON", interactive=False)
add_button.click(fn=add_entry, inputs=[title, context, question, answer, answer_start, entry_id], outputs=output)
save_button.click(fn=save_to_json, inputs=file_name, outputs=download_link)
demo.launch() |