Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai | |
from datasets import load_dataset | |
import logging | |
# Set up logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
# Initialize OpenAI API key | |
openai.api_key = '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' | |
# Load just one dataset to start | |
dataset = load_dataset("rungalileo/ragbench", "hotpotqa", split='train') | |
logger.info("Dataset loaded successfully") | |
def process_query(query): | |
try: | |
# Get a relevant document from the dataset | |
context = dataset['documents'][0] # Using first document as example | |
response = openai.chat.completions.create( | |
model="gpt-3.5-turbo", | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant for the RagBench dataset."}, | |
{"role": "user", "content": f"Context: {context}\nQuestion: {query}"} | |
], | |
max_tokens=300, | |
temperature=0.7, | |
) | |
return response.choices[0].message.content.strip() | |
except Exception as e: | |
return f"Query processing: {str(e)}" | |
# Create simple Gradio interface | |
demo = gr.Interface( | |
fn=process_query, | |
inputs=gr.Textbox(label="Question"), | |
outputs=gr.Textbox(label="Answer"), | |
title="RagBench QA System", | |
description="Ask questions about HotpotQA dataset" | |
) | |
if __name__ == "__main__": | |
demo.launch(debug=True) | |