ankban commited on
Commit
c111e1f
Β·
verified Β·
1 Parent(s): 72fb9b6

Update written_module.py

Browse files
Files changed (1) hide show
  1. written_module.py +30 -12
written_module.py CHANGED
@@ -41,7 +41,7 @@ Current text:
41
  )
42
  feedback = response.choices[0].message.content
43
 
44
- # Strip the JSON block from the feedback before returning to user
45
  try:
46
  split_idx = feedback.index('}') + 1
47
  feedback_clean = feedback[split_idx:].strip()
@@ -86,23 +86,26 @@ def written_dashboard(nickname_input):
86
  goal_dropdown = gr.Dropdown(label="🎯 Writing Goal", choices=["Essay for school", "Job application", "Blog post", "Creative writing", "General improvement"], value="General improvement")
87
  focus_checkboxes = gr.CheckboxGroup(label="🧠 Focus Areas", choices=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"], value=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"])
88
 
89
- trend_category_dropdown = gr.Dropdown(
90
- label="πŸ“ˆ Track Progress In",
91
- choices=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"],
92
- value="Clarity"
93
- )
94
-
95
  input_text = gr.Textbox(label="πŸ“ Your Writing", lines=10, elem_id="input_text", elem_classes=["text_area"], interactive=True)
96
  submit_button = gr.Button("πŸš€ Submit", variant="primary", size="sm")
97
 
98
  file_input = gr.File(label="πŸ“„ Upload Text File", file_types=[".txt", ".md"])
99
- feedback_box = gr.Textbox(label="πŸ’‘ Feedback", interactive=False, elem_id="feedback_box")
100
- improved_box = gr.Textbox(label="🎯 Improved Version", interactive=False, elem_id="improved_box")
101
  history_table = gr.Dataframe(headers=["πŸ•’ Timestamp", "🌐 Language", "✍️ Text", "πŸ“‹ Feedback"])
102
 
 
103
  with gr.Row():
104
- score_chart = gr.Plot(label="πŸ“Š Score Comparison")
105
- trend_chart = gr.Plot(label="πŸ“ˆ Progress Over Time")
 
 
 
 
 
 
 
 
106
 
107
  milestone_box = gr.Markdown(visible=False)
108
 
@@ -148,4 +151,19 @@ def written_dashboard(nickname_input):
148
  outputs=[feedback_box, improved_box, history_table, score_chart, trend_chart, milestone_box]
149
  )
150
 
151
- return written_panel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  )
42
  feedback = response.choices[0].message.content
43
 
44
+ # Strip JSON before returning
45
  try:
46
  split_idx = feedback.index('}') + 1
47
  feedback_clean = feedback[split_idx:].strip()
 
86
  goal_dropdown = gr.Dropdown(label="🎯 Writing Goal", choices=["Essay for school", "Job application", "Blog post", "Creative writing", "General improvement"], value="General improvement")
87
  focus_checkboxes = gr.CheckboxGroup(label="🧠 Focus Areas", choices=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"], value=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"])
88
 
 
 
 
 
 
 
89
  input_text = gr.Textbox(label="πŸ“ Your Writing", lines=10, elem_id="input_text", elem_classes=["text_area"], interactive=True)
90
  submit_button = gr.Button("πŸš€ Submit", variant="primary", size="sm")
91
 
92
  file_input = gr.File(label="πŸ“„ Upload Text File", file_types=[".txt", ".md"])
93
+ feedback_box = gr.Textbox(label="πŸ’‘ Feedback", interactive=False)
94
+ improved_box = gr.Textbox(label="🎯 Improved Version", interactive=False)
95
  history_table = gr.Dataframe(headers=["πŸ•’ Timestamp", "🌐 Language", "✍️ Text", "πŸ“‹ Feedback"])
96
 
97
+ # === Chart Area ===
98
  with gr.Row():
99
+ with gr.Column(scale=1):
100
+ gr.Markdown("### πŸ“Š Score Comparison")
101
+ score_chart = gr.Plot()
102
+ with gr.Column(scale=1):
103
+ trend_category_dropdown = gr.Dropdown(
104
+ label="πŸ“ˆ Track Progress In",
105
+ choices=["Clarity", "Organization", "Grammar", "Vocabulary", "Tone", "Creativity"],
106
+ value="Clarity"
107
+ )
108
+ trend_chart = gr.Plot(label="Progress Over Time")
109
 
110
  milestone_box = gr.Markdown(visible=False)
111
 
 
151
  outputs=[feedback_box, improved_box, history_table, score_chart, trend_chart, milestone_box]
152
  )
153
 
154
+ def update_trend_chart(trend_category, nickname):
155
+ if hasattr(nickname, "value"):
156
+ nickname = nickname.value
157
+ sessions = fetch_user_sessions(nickname)
158
+ dates, trend_scores = build_trend_data(sessions, trend_category)
159
+ if trend_scores:
160
+ return render_trend_chart(dates, trend_scores, trend_category)
161
+ return render_empty_chart(f"πŸ“ˆ {trend_category} Progress")
162
+
163
+ trend_category_dropdown.change(
164
+ fn=update_trend_chart,
165
+ inputs=[trend_category_dropdown, nickname_input],
166
+ outputs=[trend_chart]
167
+ )
168
+
169
+ return written_panel