Spaces:
Sleeping
Sleeping
Felipe Silva commited on
Commit ·
d59e0e8
1
Parent(s): d531571
Add botão
Browse files
app.py
CHANGED
|
@@ -30,13 +30,13 @@ def process_file(file):
|
|
| 30 |
|
| 31 |
file_size = os.path.getsize(file)
|
| 32 |
if file_size > MAX_FILE_SIZE:
|
| 33 |
-
return f"O arquivo excede o limite. Por favor, realize o upload de um arquivo que contenha no máximo {MAX_FILE_SIZE/1024/1024:.1f}MB."
|
| 34 |
|
| 35 |
texto_extraido = doc_converter(file)
|
| 36 |
if texto_extraido is None:
|
| 37 |
-
return "Não foi possível extrair o texto."
|
| 38 |
|
| 39 |
-
return texto_extraido
|
| 40 |
|
| 41 |
@spaces.GPU
|
| 42 |
def ask_question(texto_extraido, question):
|
|
@@ -67,12 +67,14 @@ def launch_app():
|
|
| 67 |
extracted_text = gr.Textbox(label="🌍 Texto extraído", lines=30)
|
| 68 |
with gr.Column():
|
| 69 |
question_input = gr.Textbox(label="📌 Faça uma pergunta ao seu documento!")
|
|
|
|
| 70 |
answer_output = gr.Textbox(label="🎩 Resposta", lines=15)
|
| 71 |
docs_sim = gr.Textbox(label="📎 Documentos similares a sua pergunta.", lines=15)
|
| 72 |
|
| 73 |
# Conecta funções
|
| 74 |
-
file_input.change(fn=process_file, inputs=file_input, outputs=extracted_text)
|
| 75 |
question_input.submit(fn=ask_question, inputs=[extracted_text, question_input], outputs=[answer_output, docs_sim])
|
|
|
|
| 76 |
|
| 77 |
demo.launch()
|
| 78 |
|
|
|
|
| 30 |
|
| 31 |
file_size = os.path.getsize(file)
|
| 32 |
if file_size > MAX_FILE_SIZE:
|
| 33 |
+
return f"O arquivo excede o limite. Por favor, realize o upload de um arquivo que contenha no máximo {MAX_FILE_SIZE/1024/1024:.1f}MB.", gr.update(interactive=False)
|
| 34 |
|
| 35 |
texto_extraido = doc_converter(file)
|
| 36 |
if texto_extraido is None:
|
| 37 |
+
return "Não foi possível extrair o texto.", gr.update(interactive=False)
|
| 38 |
|
| 39 |
+
return texto_extraido, gr.update(interactive=True)
|
| 40 |
|
| 41 |
@spaces.GPU
|
| 42 |
def ask_question(texto_extraido, question):
|
|
|
|
| 67 |
extracted_text = gr.Textbox(label="🌍 Texto extraído", lines=30)
|
| 68 |
with gr.Column():
|
| 69 |
question_input = gr.Textbox(label="📌 Faça uma pergunta ao seu documento!")
|
| 70 |
+
ask_button = gr.Button("🔍 Perguntar", variant="primary", size="lg", interactive=False)
|
| 71 |
answer_output = gr.Textbox(label="🎩 Resposta", lines=15)
|
| 72 |
docs_sim = gr.Textbox(label="📎 Documentos similares a sua pergunta.", lines=15)
|
| 73 |
|
| 74 |
# Conecta funções
|
| 75 |
+
file_input.change(fn=process_file, inputs=file_input, outputs=[extracted_text, ask_button])
|
| 76 |
question_input.submit(fn=ask_question, inputs=[extracted_text, question_input], outputs=[answer_output, docs_sim])
|
| 77 |
+
ask_button.click(fn=ask_question, inputs=[extracted_text, question_input], outputs=[answer_output, docs_sim])
|
| 78 |
|
| 79 |
demo.launch()
|
| 80 |
|