Update written_module.py
Browse files- 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
|
| 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
|
| 100 |
-
improved_box = gr.Textbox(label="π― Improved Version", interactive=False
|
| 101 |
history_table = gr.Dataframe(headers=["π Timestamp", "π Language", "βοΈ Text", "π Feedback"])
|
| 102 |
|
|
|
|
| 103 |
with gr.Row():
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|