Spaces:
Sleeping
Sleeping
File size: 1,604 Bytes
b863def 5fb5a23 b863def 5fb5a23 b863def 5fb5a23 b863def 5fb5a23 b863def 5fb5a23 b863def 5fb5a23 b863def 5fb5a23 |
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 38 39 40 41 |
import streamlit as st
import google.generativeai as genai
# Secure your API key - avoid hardcoding in public repos!
genai.configure(api_key="AIzaSyBG08vJws2ykUX7RcagXyiEMdddS2nZ7l0")
# FIX: Use the specific model name string
model = genai.GenerativeModel("gemini-1.5-flash")
st.title("📚 Personalized Study Buddy")
st.markdown("Enter a topic, choose a mode, and let AI help you learn!")
topic = st.text_input("Enter a topic (e.g., Python loops, Photosynthesis):", "")
mode = st.selectbox("Choose a mode:", ["Explain", "Quiz"])
if st.button("Go"):
if not topic.strip():
st.error("Please enter a topic!")
else:
if mode == "Explain":
prompt = f"Explain {topic} in 100 words or less, in simple terms for beginners."
else:
prompt = f"Generate 3 multiple-choice questions about {topic} with 4 options each and the correct answers."
try:
# Added a loading spinner for better UX
with st.spinner("Thinking..."):
response = model.generate_content(prompt)
# Use .text safely
if response.text:
st.markdown("### Your Study Buddy Result")
st.markdown(response.text)
else:
st.warning("The AI didn't return any text. Try a different topic.")
except Exception as e:
st.error(f"Oops! Something went wrong: {str(e)}")
st.info("Tip: Make sure your library is updated: pip install -U google-generativeai")
st.markdown("---") |