|
import gradio as gr |
|
import google.generativeai as genai |
|
import os |
|
|
|
|
|
GOOGLE_API_KEY = "AIzaSyApVlnGcD6ZW0Enu61LLKcpYPghMmDfMN0" |
|
genai.configure(api_key=GOOGLE_API_KEY) |
|
|
|
|
|
generation_config = { |
|
"temperature": 1, |
|
"top_p": 0.95, |
|
"top_k": 64, |
|
"max_output_tokens": 8192, |
|
"response_mime_type": "text/plain", |
|
} |
|
|
|
|
|
model = genai.GenerativeModel( |
|
model_name="gemini-1.5-flash", |
|
generation_config=generation_config |
|
) |
|
|
|
|
|
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 |
|
|
|
|
|
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", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|