import gradio as gr from transformers import pipeline from PyPDF2 import PdfReader # Leggi il file PDF def load_pdf(file_path): reader = PdfReader(file_path) text = "" for page in reader.pages: text += page.extract_text() return text # Carica il testo del catalogo catalogo_text = load_pdf("Catalogo IVR BC01 - Listino Prezzi.pdf") # Inizializza il modello di QA qa = pipeline("question-answering", model="distilbert-base-multilingual-cased") def chatbot(question): result = qa(question=question, context=catalogo_text) return result['answer'] # Interfaccia Gradio iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="IVR Chatbot") iface.launch()