Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from metrology_rag import MetrologyRAGPipeline # Assuming your code is in a file named metrology_rag.py
|
3 |
+
|
4 |
+
# Initialize the pipeline
|
5 |
+
rag_pipeline = MetrologyRAGPipeline()
|
6 |
+
|
7 |
+
# Function to handle user queries
|
8 |
+
def process_query(query, pdf_files):
|
9 |
+
# If PDF files are uploaded, load them into the pipeline
|
10 |
+
if pdf_files:
|
11 |
+
pdf_paths = [file.name for file in pdf_files] # Gradio uploads files to temporary paths
|
12 |
+
rag_pipeline.load_pdfs(pdf_paths=pdf_paths)
|
13 |
+
|
14 |
+
# Process the query and return the response
|
15 |
+
response = rag_pipeline.query(query)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Define the Gradio interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=process_query,
|
21 |
+
inputs=[
|
22 |
+
gr.Textbox(label="Digite sua pergunta sobre metrologia", placeholder="Ex: Avaliação do certificado de calibração..."),
|
23 |
+
gr.File(label="Carregar arquivos PDF (opcional)", file_count="multiple", type="file")
|
24 |
+
],
|
25 |
+
outputs=gr.Textbox(label="Resposta do Agente de Metrologia"),
|
26 |
+
title="Agente de Metrologia Avançado",
|
27 |
+
description="Faça perguntas técnicas sobre metrologia e carregue PDFs para análise (ex.: certificados, normas).",
|
28 |
+
theme="default"
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the app
|
32 |
+
if __name__ == "__main__":
|
33 |
+
interface.launch()
|