File size: 1,181 Bytes
bc2d9b8
7831e4e
 
8368e02
 
7831e4e
 
 
d6a08d5
7831e4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import google.generativeai as genai

# Directly configure API key (Replace with your actual API key)
genai.configure(api_key="AIzaSyD5UTVMIDrIQQwl9vRJl1aS-mEEz3gv06M")  # <-- Use string directly

# Function to generate a funny short story
def generate_funny_story(query):
    model = genai.GenerativeModel("gemini-2.0-pro-exp-02-05")
    prompt = f"Write a short and funny story based on this idea: {query}. Make it hilarious!"
    
    try:
        response = model.generate_content(prompt)
        return response.text
    except Exception as e:
        return f"Error: {str(e)}"

# Streamlit UI
st.title("😂 AI Funny Story Generator")
st.write("Give me an idea, and I'll turn it into a short, funny story!")

# User input
user_query = st.text_input("Enter your story idea (e.g., 'A dog that becomes a detective')")

# Generate story button
if st.button("Generate Story"):
    if user_query:
        story = generate_funny_story(user_query)
        st.subheader("🤣 Here’s Your Funny Story:")
        st.write(story)
    else:
        st.warning("Please enter an idea first!")

# Footer
st.markdown("---")
st.caption("Powered by Google Gemini 🚀")