Spaces:
Runtime error
Runtime error
probando el primer modelo en inglés
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
docs = None
|
| 4 |
|
|
@@ -18,28 +20,39 @@ def validate_dataset(dataset):
|
|
| 18 |
else:
|
| 19 |
return "⚠️Esperando documentos..."
|
| 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 |
with gr.Blocks() as demo:
|
|
@@ -73,7 +86,7 @@ with gr.Blocks() as demo:
|
|
| 73 |
label="Documentos y citas"
|
| 74 |
)
|
| 75 |
buildb = gr.Textbox("⚠️Esperando documentos...",
|
| 76 |
-
label="
|
| 77 |
dataset.change(validate_dataset, inputs=[
|
| 78 |
dataset], outputs=[buildb])
|
| 79 |
uploaded_files.change(request_pathname, inputs=[
|
|
@@ -87,8 +100,10 @@ with gr.Blocks() as demo:
|
|
| 87 |
gr.Markdown(
|
| 88 |
"### Contexto\n\nEl siguiente contexto ha sido utilizado para generar la respuesta:")
|
| 89 |
context = gr.Markdown(label="Contexto")
|
|
|
|
|
|
|
| 90 |
ask.click(fn=do_ask, inputs=[query, buildb,
|
| 91 |
-
dataset], outputs=[answer
|
| 92 |
|
| 93 |
demo.queue(concurrency_count=20)
|
| 94 |
demo.launch(show_error=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from pathlib import Path
|
| 4 |
|
| 5 |
docs = None
|
| 6 |
|
|
|
|
| 20 |
else:
|
| 21 |
return "⚠️Esperando documentos..."
|
| 22 |
|
| 23 |
+
def do_ask(question, button, dataset):
|
| 24 |
+
|
| 25 |
+
global docs
|
| 26 |
+
docs_ready = dataset.iloc[-1, 0] != ""
|
| 27 |
+
if button == "✨Listo✨" and docs_ready:
|
| 28 |
+
path = dataset["filepath"]
|
| 29 |
+
txt = Path('path.txt').read_text()
|
| 30 |
+
question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
|
| 31 |
+
return question_answerer(question, context=text)
|
| 32 |
+
else:
|
| 33 |
+
return ""
|
| 34 |
+
|
| 35 |
+
# def do_ask(question, button, dataset, progress=gr.Progress()):
|
| 36 |
+
# global docs
|
| 37 |
+
# docs_ready = dataset.iloc[-1, 0] != ""
|
| 38 |
+
# if button == "✨Listo✨" and docs_ready:
|
| 39 |
+
# if docs is None: # don't want to rebuild index if it's already built
|
| 40 |
+
# import paperqa
|
| 41 |
+
# docs = paperqa.Docs()
|
| 42 |
+
# # dataset is pandas dataframe
|
| 43 |
+
# for _, row in dataset.iterrows():
|
| 44 |
+
# key = None
|
| 45 |
+
# if ',' not in row['citation string']:
|
| 46 |
+
# key = row['citation string']
|
| 47 |
+
# docs.add(row['filepath'], row['citation string'], key=key)
|
| 48 |
+
# else:
|
| 49 |
+
# return ""
|
| 50 |
+
# progress(0, "Construyendo índices...")
|
| 51 |
+
# docs._build_faiss_index()
|
| 52 |
+
# progress(0.25, "Encolando...")
|
| 53 |
+
# result = docs.query(question)
|
| 54 |
+
# progress(1.0, "¡Hecho!")
|
| 55 |
+
# return result.formatted_answer, result.context
|
| 56 |
|
| 57 |
|
| 58 |
with gr.Blocks() as demo:
|
|
|
|
| 86 |
label="Documentos y citas"
|
| 87 |
)
|
| 88 |
buildb = gr.Textbox("⚠️Esperando documentos...",
|
| 89 |
+
label="Estado", interactive=False, show_label=True)
|
| 90 |
dataset.change(validate_dataset, inputs=[
|
| 91 |
dataset], outputs=[buildb])
|
| 92 |
uploaded_files.change(request_pathname, inputs=[
|
|
|
|
| 100 |
gr.Markdown(
|
| 101 |
"### Contexto\n\nEl siguiente contexto ha sido utilizado para generar la respuesta:")
|
| 102 |
context = gr.Markdown(label="Contexto")
|
| 103 |
+
# ask.click(fn=do_ask, inputs=[query, buildb,
|
| 104 |
+
# dataset], outputs=[answer, context])
|
| 105 |
ask.click(fn=do_ask, inputs=[query, buildb,
|
| 106 |
+
dataset], outputs=[answer])
|
| 107 |
|
| 108 |
demo.queue(concurrency_count=20)
|
| 109 |
demo.launch(show_error=True)
|