Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
GOOGLE_API_KEY = "
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Function to generate a funny story
|
| 9 |
def get_funny_story(query, style, length):
|
|
@@ -12,9 +18,9 @@ def get_funny_story(query, style, length):
|
|
| 12 |
f"Make it {length} sentences long and style it as {style}. "
|
| 13 |
"The story should be humorous and entertaining."
|
| 14 |
)
|
| 15 |
-
|
| 16 |
try:
|
| 17 |
-
model = genai.GenerativeModel("gemini-
|
| 18 |
response = model.generate_content(prompt)
|
| 19 |
return response.text
|
| 20 |
except Exception as e:
|
|
@@ -43,4 +49,3 @@ if st.button("Generate Funny Story"):
|
|
| 43 |
st.write(story)
|
| 44 |
else:
|
| 45 |
st.warning("Please enter a query for your story.")
|
| 46 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Securely retrieve API key from environment variables
|
| 6 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 7 |
+
|
| 8 |
+
# Ensure the API key is set before configuring Gemini
|
| 9 |
+
if GOOGLE_API_KEY:
|
| 10 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 11 |
+
else:
|
| 12 |
+
st.error("❌ API Key is missing! Please set it in Hugging Face Secrets.")
|
| 13 |
|
| 14 |
# Function to generate a funny story
|
| 15 |
def get_funny_story(query, style, length):
|
|
|
|
| 18 |
f"Make it {length} sentences long and style it as {style}. "
|
| 19 |
"The story should be humorous and entertaining."
|
| 20 |
)
|
| 21 |
+
|
| 22 |
try:
|
| 23 |
+
model = genai.GenerativeModel("gemini-pro")
|
| 24 |
response = model.generate_content(prompt)
|
| 25 |
return response.text
|
| 26 |
except Exception as e:
|
|
|
|
| 49 |
st.write(story)
|
| 50 |
else:
|
| 51 |
st.warning("Please enter a query for your story.")
|
|
|