Spaces:
Runtime error
Runtime error
import gradio as gr | |
import google.generativeai as genai | |
import os | |
# Setup | |
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_AI_STUDIO2') | |
genai.configure(api_key=GOOGLE_AI_STUDIO) | |
# Model initialization | |
model = genai.GenerativeModel('gemini-pro') | |
def get_response(query): | |
""" | |
Searches for content based on the provided query using the Gemini model. | |
Handles DeadlineExceeded exceptions from the Google API. | |
Args: | |
query (str): The search query. | |
Returns: | |
str: The response text from the Gemini model or an error message. | |
""" | |
try: | |
response = model.generate_content(query) | |
return response.text | |
except exceptions.DeadlineExceeded as e: | |
# Handle the DeadlineExceeded exception here | |
print("Error: Deadline Exceeded -", str(e)) | |
# You can return a custom message or take other appropriate actions | |
return "Error: The request timed out. Please try again later." | |
# Gradio interface | |
iface = gr.Interface( | |
fn=get_response, | |
inputs=gr.Textbox(label="Enter your query"), | |
outputs=gr.Textbox(label="Response"), | |
title="AI Content Generator", | |
description="Enter a query to generate content using Gemini Pro model." | |
) | |
iface.launch() |