Spaces:
Sleeping
Sleeping
| 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("---") |