Spaces:
Runtime error
Runtime error
File size: 1,222 Bytes
297dcf2 ef589cb 297dcf2 ef589cb 297dcf2 6a322e7 297dcf2 7ef1e32 6f0f1e3 297dcf2 ef589cb |
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 30 31 32 33 34 35 36 37 38 39 40 |
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() |