Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
-
#
|
| 5 |
def test_ai_responses():
|
| 6 |
-
st.title("π€ AI Response Debugger -
|
| 7 |
|
| 8 |
# Get API Key
|
| 9 |
api_key = st.text_input("Enter Gemini API Key:", type="password")
|
|
@@ -16,125 +16,110 @@ def test_ai_responses():
|
|
| 16 |
with tab1:
|
| 17 |
st.subheader("Test Study Plan Generation")
|
| 18 |
|
| 19 |
-
subject = st.text_input("Subject:", "
|
| 20 |
-
days_available = st.slider("Days Available:", 7, 365, 60, key="plan_days")
|
| 21 |
-
hours_per_day = st.slider("Hours per Day:", 1, 8, 2, key="plan_hours")
|
| 22 |
|
| 23 |
if st.button("Generate Test Study Plan", key="plan_btn"):
|
| 24 |
-
with st.spinner("Generating..."):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
{{
|
| 34 |
-
"subject": "{subject}",
|
| 35 |
-
"total_weeks": {weeks},
|
| 36 |
-
"daily_hours": {hours_per_day},
|
| 37 |
"study_days": ["Mon", "Tue", "Wed", "Thu", "Fri"],
|
| 38 |
-
"topics_allocation": {
|
| 39 |
"weekly_schedule": [
|
| 40 |
-
{
|
| 41 |
"week": 1,
|
| 42 |
-
"focus": "Week
|
| 43 |
"objectives": ["Objective 1", "Objective 2"],
|
| 44 |
"daily_tasks": [
|
| 45 |
-
["Task 1
|
| 46 |
-
["Task 1
|
| 47 |
-
["Task 1
|
| 48 |
-
["Task 1
|
| 49 |
-
["Task 1
|
| 50 |
],
|
| 51 |
-
"day_focus": ["Monday:
|
| 52 |
-
"week_summary": "
|
| 53 |
"resources": ["Resource 1", "Resource 2"],
|
| 54 |
-
"milestone": "
|
| 55 |
-
}
|
| 56 |
],
|
| 57 |
"study_tips": ["Tip 1", "Tip 2"],
|
| 58 |
"success_metrics": ["Metric 1", "Metric 2"]
|
| 59 |
-
}
|
|
|
|
|
|
|
| 60 |
|
| 61 |
try:
|
| 62 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 63 |
response = model.generate_content(
|
| 64 |
prompt,
|
| 65 |
generation_config=genai.GenerationConfig(
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
)
|
| 70 |
|
| 71 |
raw_text = response.text
|
| 72 |
-
st.subheader("
|
| 73 |
-
st.text_area("COPY EVERYTHING FROM HERE:", raw_text, height=600)
|
| 74 |
|
| 75 |
-
# Show
|
| 76 |
-
st.
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
st.markdown("---")
|
| 80 |
-
st.subheader("π What to do:")
|
| 81 |
-
st.write("1. Copy ALL the text from the box above")
|
| 82 |
-
st.write("2. Paste it in the chat for me to analyze")
|
| 83 |
-
st.write("3. I will create the correct JSON extraction function")
|
| 84 |
|
|
|
|
|
|
|
|
|
|
| 85 |
except Exception as e:
|
| 86 |
st.error(f"Error: {str(e)}")
|
| 87 |
|
| 88 |
with tab2:
|
| 89 |
st.subheader("Test Question Generation")
|
| 90 |
|
| 91 |
-
week_num = st.number_input("Week Number:", 1, 12, 1, key="test_week")
|
| 92 |
-
test_subject = st.text_input("Test Subject:", "Data Science", key="test_subject")
|
| 93 |
-
|
| 94 |
if st.button("Generate Test Questions", key="test_btn"):
|
| 95 |
with st.spinner("Generating test questions..."):
|
| 96 |
-
prompt =
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
{{
|
| 100 |
"questions": [
|
| 101 |
-
{
|
| 102 |
-
"question": "
|
| 103 |
-
"options": {
|
| 104 |
-
"A": "
|
| 105 |
-
"B": "
|
| 106 |
-
"C": "
|
| 107 |
-
"D": "
|
| 108 |
-
}
|
| 109 |
"correct_answer": "A",
|
| 110 |
-
"explanation": "
|
| 111 |
-
}
|
| 112 |
]
|
| 113 |
-
}
|
|
|
|
|
|
|
| 114 |
|
| 115 |
try:
|
| 116 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 117 |
response = model.generate_content(
|
| 118 |
prompt,
|
| 119 |
generation_config=genai.GenerationConfig(
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
)
|
| 124 |
|
| 125 |
raw_text = response.text
|
| 126 |
-
st.subheader("
|
| 127 |
-
st.text_area("COPY EVERYTHING FROM HERE:", raw_text, height=600)
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
-
|
| 133 |
-
st.markdown("---")
|
| 134 |
-
st.subheader("π What to do:")
|
| 135 |
-
st.write("1. Copy ALL the text from the box above")
|
| 136 |
-
st.write("2. Paste it in the chat for me to analyze")
|
| 137 |
-
st.write("3. I will create the correct JSON extraction function")
|
| 138 |
|
| 139 |
except Exception as e:
|
| 140 |
st.error(f"Error: {str(e)}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
+
# Test function to get COMPLETE AI responses
|
| 5 |
def test_ai_responses():
|
| 6 |
+
st.title("π€ AI Response Debugger - COMPLETE OUTPUT")
|
| 7 |
|
| 8 |
# Get API Key
|
| 9 |
api_key = st.text_input("Enter Gemini API Key:", type="password")
|
|
|
|
| 16 |
with tab1:
|
| 17 |
st.subheader("Test Study Plan Generation")
|
| 18 |
|
| 19 |
+
subject = st.text_input("Subject:", "Machine Learning", key="plan_subject")
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if st.button("Generate Test Study Plan", key="plan_btn"):
|
| 22 |
+
with st.spinner("Generating COMPLETE plan (this may take a moment)..."):
|
| 23 |
+
# SIMPLER prompt - let AI structure it naturally
|
| 24 |
+
prompt = """Create a complete 4-week study plan for Machine Learning.
|
| 25 |
+
Return the plan as valid JSON with this structure:
|
| 26 |
+
{
|
| 27 |
+
"subject": "Machine Learning",
|
| 28 |
+
"total_weeks": 4,
|
| 29 |
+
"daily_hours": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
"study_days": ["Mon", "Tue", "Wed", "Thu", "Fri"],
|
| 31 |
+
"topics_allocation": {"Python Basics": 10, "Statistics": 15, "ML Algorithms": 25, "Projects": 20},
|
| 32 |
"weekly_schedule": [
|
| 33 |
+
{
|
| 34 |
"week": 1,
|
| 35 |
+
"focus": "Week 1 focus",
|
| 36 |
"objectives": ["Objective 1", "Objective 2"],
|
| 37 |
"daily_tasks": [
|
| 38 |
+
["Task 1 Monday", "Task 2 Monday"],
|
| 39 |
+
["Task 1 Tuesday", "Task 2 Tuesday"],
|
| 40 |
+
["Task 1 Wednesday", "Task 2 Wednesday"],
|
| 41 |
+
["Task 1 Thursday", "Task 2 Thursday"],
|
| 42 |
+
["Task 1 Friday", "Task 2 Friday"]
|
| 43 |
],
|
| 44 |
+
"day_focus": ["Monday: Intro", "Tuesday: Practice", "Wednesday: Deep Dive", "Thursday: Review", "Friday: Project"],
|
| 45 |
+
"week_summary": "Week 1 summary",
|
| 46 |
"resources": ["Resource 1", "Resource 2"],
|
| 47 |
+
"milestone": "Complete Week 1"
|
| 48 |
+
}
|
| 49 |
],
|
| 50 |
"study_tips": ["Tip 1", "Tip 2"],
|
| 51 |
"success_metrics": ["Metric 1", "Metric 2"]
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
Make sure to include ALL 4 weeks in the weekly_schedule array."""
|
| 55 |
|
| 56 |
try:
|
| 57 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 58 |
response = model.generate_content(
|
| 59 |
prompt,
|
| 60 |
generation_config=genai.GenerationConfig(
|
| 61 |
+
max_output_tokens=4000, # INCREASED for complete response
|
| 62 |
+
temperature=0.7
|
| 63 |
+
)
|
| 64 |
)
|
| 65 |
|
| 66 |
raw_text = response.text
|
| 67 |
+
st.subheader("COMPLETE RAW AI RESPONSE:")
|
|
|
|
| 68 |
|
| 69 |
+
# Show in expander for better viewing
|
| 70 |
+
with st.expander("π Click to view FULL response", expanded=True):
|
| 71 |
+
st.text_area("COPY EVERYTHING BELOW:", raw_text, height=800, key="plan_raw")
|
| 72 |
|
| 73 |
+
st.info(f"β
Response length: {len(raw_text)} characters")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
if len(raw_text) < 500:
|
| 76 |
+
st.warning("β οΈ Response seems too short! The AI might have stopped early.")
|
| 77 |
+
|
| 78 |
except Exception as e:
|
| 79 |
st.error(f"Error: {str(e)}")
|
| 80 |
|
| 81 |
with tab2:
|
| 82 |
st.subheader("Test Question Generation")
|
| 83 |
|
|
|
|
|
|
|
|
|
|
| 84 |
if st.button("Generate Test Questions", key="test_btn"):
|
| 85 |
with st.spinner("Generating test questions..."):
|
| 86 |
+
prompt = """Create 3 multiple choice questions for Machine Learning.
|
| 87 |
+
Return valid JSON with this structure:
|
| 88 |
+
{
|
|
|
|
| 89 |
"questions": [
|
| 90 |
+
{
|
| 91 |
+
"question": "What is supervised learning?",
|
| 92 |
+
"options": {
|
| 93 |
+
"A": "Learning with labeled data",
|
| 94 |
+
"B": "Learning without labeled data",
|
| 95 |
+
"C": "Reinforcement learning",
|
| 96 |
+
"D": "Deep learning"
|
| 97 |
+
},
|
| 98 |
"correct_answer": "A",
|
| 99 |
+
"explanation": "Supervised learning uses labeled data to train models."
|
| 100 |
+
}
|
| 101 |
]
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
Include exactly 3 questions."""
|
| 105 |
|
| 106 |
try:
|
| 107 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 108 |
response = model.generate_content(
|
| 109 |
prompt,
|
| 110 |
generation_config=genai.GenerationConfig(
|
| 111 |
+
max_output_tokens=2000,
|
| 112 |
+
temperature=0.7
|
| 113 |
+
)
|
| 114 |
)
|
| 115 |
|
| 116 |
raw_text = response.text
|
| 117 |
+
st.subheader("COMPLETE RAW AI RESPONSE:")
|
|
|
|
| 118 |
|
| 119 |
+
with st.expander("π Click to view FULL response", expanded=True):
|
| 120 |
+
st.text_area("COPY EVERYTHING BELOW:", raw_text, height=600, key="test_raw")
|
| 121 |
|
| 122 |
+
st.info(f"β
Response length: {len(raw_text)} characters")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
except Exception as e:
|
| 125 |
st.error(f"Error: {str(e)}")
|