Spaces:
Runtime error
Runtime error
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() | |