Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,81 +5,77 @@
|
|
| 5 |
|
| 6 |
import os
|
| 7 |
import json
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
)
|
| 69 |
-
return response.text, "gemini"
|
| 70 |
-
except Exception as e:
|
| 71 |
-
print(f"β Gemini attempt {attempt+1} failed: {e}")
|
| 72 |
-
if attempt < max_retries - 1:
|
| 73 |
-
time.sleep(1)
|
| 74 |
-
|
| 75 |
-
if image:
|
| 76 |
-
return " Image analysis requires Gemini AI. Please check API configuration.", "error"
|
| 77 |
-
|
| 78 |
-
# Try Cohere (Secondary) - text only
|
| 79 |
-
if cohere_client:
|
| 80 |
-
for attempt in range(max_retries):
|
| 81 |
-
try:
|
| 82 |
-
response = cohere_client.chat(
|
| 83 |
model="command-r-plus-08-2024",
|
| 84 |
message=prompt,
|
| 85 |
temperature=temperature
|
|
|
|
| 5 |
|
| 6 |
import os
|
| 7 |
import json
|
| 8 |
+
with gr.Tabs():
|
| 9 |
+
with gr.Tab("βοΈ Draw Answers"):
|
| 10 |
+
canvas = gr.Sketchpad(
|
| 11 |
+
label="Draw or write your answers here",
|
| 12 |
+
type="pil",
|
| 13 |
+
height=500,
|
| 14 |
+
brush=gr.Brush(
|
| 15 |
+
colors=["#000000", "#0000FF", "#FF0000"],
|
| 16 |
+
default_size=4
|
| 17 |
+
)
|
| 18 |
+
)
|
| 19 |
+
canvas_status = gr.Textbox(
|
| 20 |
+
label="Canvas Status",
|
| 21 |
+
interactive=False,
|
| 22 |
+
value="Ready to draw"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
with gr.Tab("πΈ Upload Photo"):
|
| 26 |
+
upload_image = gr.Image(
|
| 27 |
+
label="Upload photo of your written work",
|
| 28 |
+
type="pil",
|
| 29 |
+
height=500
|
| 30 |
+
)
|
| 31 |
+
upload_status = gr.Textbox(
|
| 32 |
+
label="Upload Status",
|
| 33 |
+
interactive=False,
|
| 34 |
+
value="Ready to upload"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
with gr.Tab(" Type Answers"):
|
| 38 |
+
gr.Markdown("""
|
| 39 |
+
### π Type Your Answers
|
| 40 |
+
**Instructions:** Type each answer in the box below. Use one of these formats:
|
| 41 |
+
- **Option A (Recommended):** Type answers separated by blank lines
|
| 42 |
+
```
|
| 43 |
+
Answer to question 1 goes here
|
| 44 |
+
|
| 45 |
+
Answer to question 2 goes here
|
| 46 |
+
|
| 47 |
+
Answer to question 3 goes here
|
| 48 |
+
```
|
| 49 |
+
- **Option B:** Type with labels
|
| 50 |
+
```
|
| 51 |
+
Answer 1: Your answer here
|
| 52 |
+
Answer 2: Your answer here
|
| 53 |
+
Answer 3: Your answer here
|
| 54 |
+
```
|
| 55 |
+
- **Option C:** Type with Q labels
|
| 56 |
+
```
|
| 57 |
+
Q1: Your answer here
|
| 58 |
+
Q2: Your answer here
|
| 59 |
+
Q3: Your answer here
|
| 60 |
+
```
|
| 61 |
+
""")
|
| 62 |
+
|
| 63 |
+
typed_answers = gr.Textbox(
|
| 64 |
+
label="Type Your Answers Here",
|
| 65 |
+
lines=20,
|
| 66 |
+
placeholder="Type your answers using any of the formats shown above...",
|
| 67 |
+
elem_classes="answer-input"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# Combined submit button (outside tabs, still inside right column)
|
| 71 |
+
with gr.Row():
|
| 72 |
+
submit_btn = gr.Button(" Submit for Correction", variant="primary", size="lg")
|
| 73 |
+
|
| 74 |
+
submit_status = gr.Textbox(
|
| 75 |
+
label="Submission Status",
|
| 76 |
+
interactive=False,
|
| 77 |
+
lines=2
|
| 78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
model="command-r-plus-08-2024",
|
| 80 |
message=prompt,
|
| 81 |
temperature=temperature
|