Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
from transformers import pipeline | |
import spaces | |
# Load CSV data | |
data = pd.read_csv('documents.csv') | |
# Load a transformer model (you can choose a suitable model from Hugging Face) | |
# For this example, we'll use a simple QA model | |
qa_model = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") | |
# Function to retrieve the relevant document and generate a response | |
def retrieve_and_generate(question): | |
# Combine all abstracts into a single string (you can improve this by better retrieval methods) | |
abstracts = " ".join(data['Abstract'].fillna("").tolist()) | |
# Retrieve the most relevant section from the combined abstracts | |
response = qa_model(question=question, context=abstracts) | |
return response['answer'] | |
# Create a Gradio interface | |
interface = gr.Interface( | |
fn=retrieve_and_generate, | |
inputs=gr.inputs.Textbox(lines=2, placeholder="Ask a question about the documents..."), | |
outputs="text", | |
title="RAG Chatbot", | |
description="Ask questions about the documents in the CSV file." | |
) | |
# Launch the Gradio app | |
interface.launch() | |