chatbot / app.py
admin08077's picture
Create app.py
8977e54 verified
raw
history blame
1.71 kB
import os
import gradio as gr
import google.generativeai as genai
# Configure the Google Generative AI
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
# Create the model
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,
)
# Initialize a chat session
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"tell me a story about me",
],
},
{
"role": "model",
"parts": [
"Please tell me a little bit about yourself! I need some information to write a story about you. For example:\n\n* **What are your hobbies and interests?** \n* **What are some of your favorite things?** \n* **What kind of story do you want to hear?** (Adventure, romance, mystery, etc.)\n* **Is there anything unique or interesting about you that you'd like to see in the story?**\n\nOnce I know more about you, I can write a fun and engaging story just for you! 😊 \n",
],
},
]
)
def generate_story(user_input):
response = chat_session.send_message(user_input)
return response.text
# Create a Gradio Interface
iface = gr.Interface(
fn=generate_story,
inputs=gr.Textbox(lines=4, placeholder="Enter some information about yourself..."),
outputs="text",
title="AI Story Generator",
description="Enter some details about yourself, and the AI will generate a personalized story for you!"
)
# Launch the interface
iface.launch()