YU-XI commited on
Commit
405f754
·
verified ·
1 Parent(s): 64b1b20

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+
4
+ # Configure Gemini API
5
+ genai.configure(api_key='AIzaSyBIPYXqIvI1X6unKTbuWqcVfNFCePr8_sQ')
6
+ model = genai.GenerativeModel('gemini-pro')
7
+
8
+ def generate_response(user_message):
9
+ try:
10
+ # Use Gemini API to generate a response
11
+ response = model.generate_content(user_message)
12
+
13
+ # Check if the response has text
14
+ if response.text:
15
+ return response.text
16
+ else:
17
+ return "Error: The model generated an empty response."
18
+ except Exception as e:
19
+ return f"An error occurred: {str(e)}"
20
+
21
+ # Create Gradio interface
22
+ iface = gr.Interface(
23
+ fn=generate_response,
24
+ inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
25
+ outputs=gr.Textbox(label="Gemini's Response"),
26
+ title="Gemini QA System",
27
+ description="Ask a question and get an answer from Gemini AI.",
28
+ examples=[
29
+ ["What is the capital of France?"],
30
+ ["Explain quantum computing in simple terms."]
31
+ ]
32
+ )
33
+
34
+ # Launch the interface
35
+ iface.launch(debug=True)