prasanthr0416 commited on
Commit
7136db1
Β·
verified Β·
1 Parent(s): b0be3af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -75
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import streamlit as st
2
  import google.generativeai as genai
3
 
4
- # Simple test function to show FULL raw AI responses
5
  def test_ai_responses():
6
- st.title("πŸ€– AI Response Debugger - RAW OUTPUT ONLY")
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:", "Data Science", key="plan_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
- weeks = max(1, days_available // 7)
26
-
27
- prompt = f"""Create a detailed {weeks}-week study plan for: {subject}
28
-
29
- Study schedule: {hours_per_day} hours/day, 5 days/week (Monday to Friday)
30
-
31
- IMPORTANT: Return JSON ONLY with this exact structure:
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": {{"Topic1": 10, "Topic2": 20, "Topic3": 30}},
39
  "weekly_schedule": [
40
- {{
41
  "week": 1,
42
- "focus": "Week focus title",
43
  "objectives": ["Objective 1", "Objective 2"],
44
  "daily_tasks": [
45
- ["Task 1 for Monday", "Task 2 for Monday"],
46
- ["Task 1 for Tuesday", "Task 2 for Tuesday"],
47
- ["Task 1 for Wednesday", "Task 2 for Wednesday"],
48
- ["Task 1 for Thursday", "Task 2 for Thursday"],
49
- ["Task 1 for Friday", "Task 2 for Friday"]
50
  ],
51
- "day_focus": ["Monday: Introduction", "Tuesday: Practice", "Wednesday: Deep Dive", "Thursday: Review", "Friday: Project"],
52
- "week_summary": "Brief summary",
53
  "resources": ["Resource 1", "Resource 2"],
54
- "milestone": "Weekly 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
- max_output_tokens=2000,
67
- temperature=0.7
68
- )
69
  )
70
 
71
  raw_text = response.text
72
- st.subheader("FULL RAW AI RESPONSE:")
73
- st.text_area("COPY EVERYTHING FROM HERE:", raw_text, height=600)
74
 
75
- # Show length info
76
- st.info(f"Response length: {len(raw_text)} characters")
 
77
 
78
- # Just show the raw text - NO PARSING ATTEMPT
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 = f"""Create 5 multiple choice questions for Week {week_num} of {test_subject}.
97
-
98
- Return JSON:
99
- {{
100
  "questions": [
101
- {{
102
- "question": "Clear, complete question?",
103
- "options": {{
104
- "A": "Complete option A text with full explanation",
105
- "B": "Complete option B text with full explanation",
106
- "C": "Complete option C text with full explanation",
107
- "D": "Complete option D text with full explanation"
108
- }},
109
  "correct_answer": "A",
110
- "explanation": "Brief explanation of correct answer"
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
- max_output_tokens=1200,
121
- temperature=0.7
122
- )
123
  )
124
 
125
  raw_text = response.text
126
- st.subheader("FULL RAW AI RESPONSE:")
127
- st.text_area("COPY EVERYTHING FROM HERE:", raw_text, height=600)
128
 
129
- # Show length info
130
- st.info(f"Response length: {len(raw_text)} characters")
131
 
132
- # Just show the raw text - NO PARSING ATTEMPT
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)}")