Spaces:
Sleeping
Sleeping
| import os | |
| import google.generativeai as genai | |
| import gradio as gr | |
| # Configure the API key for Google Generative AI | |
| GOOGLE_API_KEY = "AIzaSyA9Bh3WRz6LzKaA7MDm6foj1dw8w8kh-gc" | |
| genai.configure(api_key=GOOGLE_API_KEY) | |
| # Set up the generation configuration | |
| generation_config = { | |
| "temperature": 1, | |
| "top_p": 0.95, | |
| "top_k": 64, | |
| "max_output_tokens": 8192, | |
| "response_mime_type": "text/plain", | |
| } | |
| # Load the model (Gemini 1.5 flash in this case) | |
| model = genai.GenerativeModel( | |
| model_name="gemini-1.5-flash", | |
| generation_config=generation_config, | |
| ) | |
| # Function to handle conversation | |
| def generate_response(user_input): | |
| chat_session = model.start_chat( | |
| history=[{ | |
| "role": "user", | |
| "parts": [user_input], | |
| }] | |
| ) | |
| response = chat_session.send_message(user_input) | |
| return response.text | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=generate_response, | |
| inputs="text", | |
| outputs="text", | |
| title="Recipe Generator", | |
| description="Ask for recipes or any other text-based generation using Google's Gemini AI", | |
| theme="default", | |
| ) | |
| # Launch the Gradio app | |
| if __name__ == "__main__": | |
| iface.launch() |