File size: 1,164 Bytes
8b582d7
921072e
 
8e2a2a1
921072e
 
 
 
 
 
 
 
 
8e2a2a1
921072e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cb1a88
 
921072e
 
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
34
35
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
@spaces.GPU(duration=120)
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()