hfariborzi commited on
Commit
ecc96a4
·
verified ·
1 Parent(s): 6d87920

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,9 +1,15 @@
1
  import streamlit as st
2
  import google.generativeai as genai
 
3
 
4
- # Configure Gemini API (Replace with your own API key)
5
- GOOGLE_API_KEY = "AIzaSyB2Nlj3u9DQ4CbpMJkw70j1MvP4xELcSuo"
6
- genai.configure(api_key=GOOGLE_API_KEY)
 
 
 
 
 
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-2.0-pro-exp-02-05")
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.")