File size: 2,412 Bytes
1d91ffa
 
 
4d16da0
1d91ffa
 
 
 
 
4beb772
73ab43d
4beb772
4d16da0
 
 
bc10f71
9ed9be5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d16da0
1d91ffa
9ed9be5
 
1d91ffa
 
4beb772
1d91ffa
9ed9be5
4d16da0
1d91ffa
 
 
 
 
8dfd657
1d91ffa
 
9ed9be5
1d91ffa
4d16da0
1d91ffa
 
4d16da0
 
 
9ed9be5
 
 
 
 
1d91ffa
 
 
 
9ed9be5
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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")

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 = 'YOUR_API_KEY'

# 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 relevant documents
        context = dataset['documents'][0]
        
        response = openai.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a confident expert assistant. Provide direct, clear answers based on the available information. Focus on what you can determine from the context and suggest exploring related topics when needed. Never apologize - maintain a positive, solution-focused tone."},
                {"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"Let's explore information about {query} from other sections of our database. What specific aspects would you like to know more about?"

# 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",
    examples=[
        ["What role does T-cell count play in severe human adenovirus type 55 (HAdV-55) infection?"],
        ["In what school district is Governor John R. Rogers High School located?"],
    ]
)

if __name__ == "__main__":
    demo.launch(debug=True)