recepie / app.py
Siri23's picture
Update app.py
90ae42b verified
import gradio as gr
import google.generativeai as genai
import os
# Configure the API key for Google Generative AI
GOOGLE_API_KEY = "AIzaSyApVlnGcD6ZW0Enu61LLKcpYPghMmDfMN0"
genai.configure(api_key=GOOGLE_API_KEY)
# Model configuration
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
# Initialize the model
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config
)
# Define a function to process the input and generate a response
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()