File size: 1,066 Bytes
405f754
 
 
 
26470b3
405f754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 google.generativeai as genai

# Configure Gemini API
genai.configure(api_key='AIzaSyBcGzp4xqhpM3K3g7J_2xAr55Sy_rE0n1g')
model = genai.GenerativeModel('gemini-pro')

def generate_response(user_message):
    try:
        # Use Gemini API to generate a response
        response = model.generate_content(user_message)

        # Check if the response has text
        if response.text:
            return response.text
        else:
            return "Error: The model generated an empty response."
    except Exception as e:
        return f"An error occurred: {str(e)}"

# Create Gradio interface
iface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
    outputs=gr.Textbox(label="Gemini's Response"),
    title="Gemini QA System",
    description="Ask a question and get an answer from Gemini AI.",
    examples=[
        ["What is the capital of France?"],
        ["Explain quantum computing in simple terms."]
    ]
)

# Launch the interface
iface.launch(debug=True)