louiecerv commited on
Commit
77c46e8
·
1 Parent(s): a3f9834

sync with remote

Browse files
Files changed (2) hide show
  1. app.py +83 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ MODEL_ID = "gemini-2.0-flash-exp"
6
+ try:
7
+ api_key = os.getenv("GEMINI_API_KEY")
8
+ model_id = MODEL_ID
9
+ genai.configure(api_key=api_key)
10
+ except Exception as e:
11
+ st.error(f"Error: {e}")
12
+ st.stop()
13
+
14
+ # Initialize conversation history in Streamlit session state
15
+ if "conversation_history" not in st.session_state:
16
+ st.session_state.conversation_history = []
17
+
18
+ # Initialize chat model outside the function to maintain state
19
+ if "chat_model" not in st.session_state:
20
+ st.session_state.chat_model = genai.GenerativeModel(MODEL_ID).start_chat(history=st.session_state.conversation_history)
21
+
22
+ def basic_prompt(text_prompt):
23
+ try:
24
+ chat = st.session_state.chat_model #use the saved chat model.
25
+ response = chat.send_message(text_prompt)
26
+
27
+ # Update conversation history
28
+ st.session_state.conversation_history.append({"role": "user", "parts": [text_prompt]}) #gemini uses parts now.
29
+ st.session_state.conversation_history.append({"role": "model", "parts": [response.text]})
30
+
31
+ # Update the chat model's history
32
+ st.session_state.chat_model = genai.GenerativeModel(MODEL_ID).start_chat(history=st.session_state.conversation_history)
33
+
34
+ return response.text
35
+ except Exception as e:
36
+ return f"An error occurred: {e}"
37
+
38
+ # App title
39
+ st.title("Gemini Tutor: One-way ANOVA and two-way ANOVA")
40
+
41
+ # About this App section
42
+ with st.expander("About this App"):
43
+ st.markdown("""
44
+ **Gemini AI-enabled Teaching Assistant** is an innovative application designed to unlock concepts in various subjects using the power of Gemini AI.
45
+ Created by Louie F. Cervantes, M. Eng. (Information Engineering) (c) 2025.
46
+ """)
47
+
48
+ # Create two tabs
49
+ st.write("Click the tabs to display more information.")
50
+ tab1, tab2 = st.tabs(["Concept", "Application"])
51
+
52
+ # Concept tab
53
+ with tab1:
54
+ prompt = """Create a detailed explainer on ANOVA statistic and the difference between one-way and two-way ANOVA.
55
+ The context is for senior high school students enrolled in a statistics course.
56
+ Use brief and concise phrasing and do not add text like 'Okay let's start' or 'Here is the explanation'."""
57
+
58
+ if st.button("Explain"):
59
+ with st.spinner("Gemini is thinking..."):
60
+ response_text = basic_prompt(prompt)
61
+ st.markdown(response_text)
62
+
63
+
64
+ # Application tab
65
+ with tab2:
66
+
67
+ st.write("Click the button to generate a new example.")
68
+
69
+ if st.button("Illustrate with an example"):
70
+ with st.spinner("Gemini is thinking..."):
71
+ prompt = """Create a real world example that uses either one-way or two-way ANOVA.
72
+ Output only the text of the example do not add any other text.
73
+ The problem should be different from the example you created in the previous step."""
74
+
75
+ problem = basic_prompt(prompt)
76
+ st.markdown(problem)
77
+
78
+ st.subheader("Explanation")
79
+ prompt = """Discuss why one-way ANOVA or two-way ANOVA is applicable and not the other."""
80
+ solution = basic_prompt(prompt)
81
+ st.markdown(solution)
82
+
83
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ markdown