eaglelandsonce commited on
Commit
0feca4f
·
1 Parent(s): 6a322e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -33
app.py CHANGED
@@ -1,40 +1,21 @@
1
- import gradio as gr
2
- import google.generativeai as genai
3
  import os
 
 
4
 
5
- # Setup
6
  GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2')
7
- genai.configure(api_key=GOOGLE_AI_STUDIO)
8
 
9
- # Model initialization
10
- model = genai.GenerativeModel('gemini-pro')
11
-
12
- def get_response(query):
13
- """
14
- Searches for content based on the provided query using the Gemini model.
15
- Handles DeadlineExceeded exceptions from the Google API.
16
- Args:
17
- query (str): The search query.
18
- Returns:
19
- str: The response text from the Gemini model or an error message.
20
- """
21
- try:
22
- response = model.generate_content(query)
23
- return response.text
24
- except exceptions.DeadlineExceeded as e:
25
- # Handle the DeadlineExceeded exception here
26
- print("Error: Deadline Exceeded -", str(e))
27
- # You can return a custom message or take other appropriate actions
28
- return "Error: The request timed out. Please try again later."
29
 
 
 
 
30
 
31
- # Gradio interface
32
- iface = gr.Interface(
33
- fn=get_response,
34
- inputs=gr.Textbox(label="Enter your query"),
35
- outputs=gr.Textbox(label="Response"),
36
- title="AI Content Generator",
37
- description="Enter a query to generate content using Gemini Pro model."
38
- )
39
 
40
- iface.launch()
 
 
 
 
1
  import os
2
+ import google.generativeai as genai
3
+ import gradio as gr
4
 
5
+ # Retrieve API Key from Environment Variable
6
  GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2')
 
7
 
8
+ # Ensure the API key is available
9
+ if not GOOGLE_AI_STUDIO:
10
+ raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Rest of your code remains the same
13
+ genai.configure(api_key=GOOGLE_AI_STUDIO)
14
+ model = genai.GenerativeModel('gemini-pro')
15
 
16
+ def generate_response(query):
17
+ response = model.generate_content(query)
18
+ return response.text
 
 
 
 
 
19
 
20
+ iface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="Generative AI Query Response")
21
+ iface.launch()