Spaces:
Sleeping
Sleeping
File size: 701 Bytes
a55942f 7879c03 d444c4e 7879c03 |
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 |
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() |