File size: 1,248 Bytes
8a359ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from metrology_rag import MetrologyRAGPipeline  # Assuming your code is in a file named metrology_rag.py

# Initialize the pipeline
rag_pipeline = MetrologyRAGPipeline()

# Function to handle user queries
def process_query(query, pdf_files):
    # If PDF files are uploaded, load them into the pipeline
    if pdf_files:
        pdf_paths = [file.name for file in pdf_files]  # Gradio uploads files to temporary paths
        rag_pipeline.load_pdfs(pdf_paths=pdf_paths)
    
    # Process the query and return the response
    response = rag_pipeline.query(query)
    return response

# Define the Gradio interface
interface = gr.Interface(
    fn=process_query,
    inputs=[
        gr.Textbox(label="Digite sua pergunta sobre metrologia", placeholder="Ex: Avaliação do certificado de calibração..."),
        gr.File(label="Carregar arquivos PDF (opcional)", file_count="multiple", type="file")
    ],
    outputs=gr.Textbox(label="Resposta do Agente de Metrologia"),
    title="Agente de Metrologia Avançado",
    description="Faça perguntas técnicas sobre metrologia e carregue PDFs para análise (ex.: certificados, normas).",
    theme="default"
)

# Launch the app
if __name__ == "__main__":
    interface.launch()