Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
-
|
| 5 |
genai.configure(api_key="AIzaSyBG08vJws2ykUX7RcagXyiEMdddS2nZ7l0")
|
|
|
|
|
|
|
| 6 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 7 |
|
| 8 |
st.title("📚 Personalized Study Buddy")
|
|
@@ -12,24 +14,28 @@ topic = st.text_input("Enter a topic (e.g., Python loops, Photosynthesis):", "")
|
|
| 12 |
mode = st.selectbox("Choose a mode:", ["Explain", "Quiz"])
|
| 13 |
|
| 14 |
if st.button("Go"):
|
| 15 |
-
if topic.strip()
|
| 16 |
st.error("Please enter a topic!")
|
| 17 |
else:
|
| 18 |
if mode == "Explain":
|
| 19 |
prompt = f"Explain {topic} in 100 words or less, in simple terms for beginners."
|
| 20 |
else:
|
| 21 |
prompt = f"Generate 3 multiple-choice questions about {topic} with 4 options each and the correct answers."
|
|
|
|
| 22 |
try:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
except Exception as e:
|
| 31 |
st.error(f"Oops! Something went wrong: {str(e)}")
|
| 32 |
-
st.
|
| 33 |
|
| 34 |
-
st.markdown("---")
|
| 35 |
-
st.write("Built with ❤️ by Ayush.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
+
# Secure your API key - avoid hardcoding in public repos!
|
| 5 |
genai.configure(api_key="AIzaSyBG08vJws2ykUX7RcagXyiEMdddS2nZ7l0")
|
| 6 |
+
|
| 7 |
+
# FIX: Use the specific model name string
|
| 8 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 9 |
|
| 10 |
st.title("📚 Personalized Study Buddy")
|
|
|
|
| 14 |
mode = st.selectbox("Choose a mode:", ["Explain", "Quiz"])
|
| 15 |
|
| 16 |
if st.button("Go"):
|
| 17 |
+
if not topic.strip():
|
| 18 |
st.error("Please enter a topic!")
|
| 19 |
else:
|
| 20 |
if mode == "Explain":
|
| 21 |
prompt = f"Explain {topic} in 100 words or less, in simple terms for beginners."
|
| 22 |
else:
|
| 23 |
prompt = f"Generate 3 multiple-choice questions about {topic} with 4 options each and the correct answers."
|
| 24 |
+
|
| 25 |
try:
|
| 26 |
+
# Added a loading spinner for better UX
|
| 27 |
+
with st.spinner("Thinking..."):
|
| 28 |
+
response = model.generate_content(prompt)
|
| 29 |
+
|
| 30 |
+
# Use .text safely
|
| 31 |
+
if response.text:
|
| 32 |
+
st.markdown("### Your Study Buddy Result")
|
| 33 |
+
st.markdown(response.text)
|
| 34 |
+
else:
|
| 35 |
+
st.warning("The AI didn't return any text. Try a different topic.")
|
| 36 |
+
|
| 37 |
except Exception as e:
|
| 38 |
st.error(f"Oops! Something went wrong: {str(e)}")
|
| 39 |
+
st.info("Tip: Make sure your library is updated: pip install -U google-generativeai")
|
| 40 |
|
| 41 |
+
st.markdown("---")
|
|
|