Spaces:
Runtime error
Runtime error
File size: 959 Bytes
ef589cb 0feca4f 297dcf2 0feca4f ef589cb 297dcf2 0feca4f 6a322e7 0feca4f 297dcf2 0feca4f bd5f25e 297dcf2 0feca4f |
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 |
import os
import google.generativeai as genai
import gradio as gr
# Retrieve API Key from Environment Variable
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2')
# Ensure the API key is available
if not GOOGLE_AI_STUDIO:
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
# Rest of your code remains the same
genai.configure(api_key=GOOGLE_AI_STUDIO)
model = genai.GenerativeModel('gemini-pro')
def generate_response(query):
try:
response = model.generate_content(query)
return response.text
except exceptions.DeadlineExceeded as e:
print("Deadline Exceeded Error: ", e)
return "Error: Deadline Exceeded"
except Exception as e:
print("An unexpected error occurred: ", e)
return "Error: An unexpected error occurred"
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="Generative AI Query Response")
iface.launch()
|