Spaces:
Sleeping
Sleeping
File size: 1,180 Bytes
bba7d00 1a540b4 bba7d00 1a540b4 bba7d00 1a540b4 |
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 41 42 43 44 45 46 47 48 |
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() |