File size: 1,928 Bytes
17312e6
a512d67
7c881b7
 
17312e6
 
a512d67
7c881b7
17312e6
7c881b7
 
17312e6
7c881b7
 
 
 
 
 
 
 
 
a512d67
7c881b7
a512d67
7c881b7
 
 
 
 
 
a512d67
7c881b7
a512d67
7c881b7
a512d67
 
7c881b7
 
 
a512d67
 
 
7c881b7
 
 
 
 
 
a512d67
7c881b7
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
from google import genai
from google.genai import types
import json
from PIL import Image

# Page config
st.set_page_config(page_title="Gemini API Physics Questions", layout="wide")

# Title
st.title("AP Physics C Practice Question Generator")

# Initialize the API key input
api_key = st.text_input("Enter your Google API Key", type="password")

if api_key:
    # Initialize the client
    client = genai.Client(
        api_key=api_key,
        http_options={'api_version': 'v1alpha'},
    )
    
    model_name = "gemini-2.0-flash-thinking-exp-01-21"
    
    if st.button("Generate New Question"):
        # Create containers for thinking and answer
        thinking_container = st.container()
        answer_container = st.container()
        
        # Generate content
        response = client.models.generate_content_stream(
            model=model_name,
            config={'thinking_config': {'include_thoughts': True}},
            contents="Give me a practice question I can use for the AP Physics C exam?"
        )
        
        mode = 'starting'
        
        # Process the response
        for chunk in response:
            for part in chunk.candidates[0].content.parts:
                if part.thought:
                    if mode != "thinking":
                        with thinking_container:
                            st.subheader("Thinking Process")
                        mode = "thinking"
                    with thinking_container:
                        st.write(part.text)
                else:
                    if mode != "answering":
                        with answer_container:
                            st.subheader("Generated Question")
                        mode = "answering"
                    with answer_container:
                        st.write(part.text)
else:
    st.warning("Please enter your Google API key to start generating questions.")