Spaces:
Sleeping
Sleeping
Commit
·
6c5b6cf
1
Parent(s):
a349175
Changed page title and added error handling
Browse files
app.py
CHANGED
|
@@ -8,15 +8,21 @@ from tutor import Tutor
|
|
| 8 |
|
| 9 |
|
| 10 |
def submit_chat(tutor_ctx, message):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def submit_code(tutor_ctx, editor, output):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def init_tutor(instructions, starter_code):
|
|
@@ -51,7 +57,7 @@ def load_level(request: gr.Request):
|
|
| 51 |
return [instructions, starter_code]
|
| 52 |
|
| 53 |
|
| 54 |
-
with gr.Blocks() as demo:
|
| 55 |
tutor_ctx = gr.State()
|
| 56 |
with gr.Row():
|
| 57 |
instruction_panel = gr.Markdown()
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def submit_chat(tutor_ctx, message):
|
| 11 |
+
try:
|
| 12 |
+
tutor = Tutor(context=tutor_ctx)
|
| 13 |
+
for history in tutor.chat(message):
|
| 14 |
+
yield [tutor.serialize(), history, None]
|
| 15 |
+
except Exception as error:
|
| 16 |
+
raise gr.Error(str(error))
|
| 17 |
|
| 18 |
|
| 19 |
def submit_code(tutor_ctx, editor, output):
|
| 20 |
+
try:
|
| 21 |
+
tutor = Tutor(context=tutor_ctx)
|
| 22 |
+
for history in tutor.code(editor, output):
|
| 23 |
+
yield [tutor.serialize(), history, None]
|
| 24 |
+
except Exception as error:
|
| 25 |
+
raise gr.Error(str(error))
|
| 26 |
|
| 27 |
|
| 28 |
def init_tutor(instructions, starter_code):
|
|
|
|
| 57 |
return [instructions, starter_code]
|
| 58 |
|
| 59 |
|
| 60 |
+
with gr.Blocks(title="CS Tutor") as demo:
|
| 61 |
tutor_ctx = gr.State()
|
| 62 |
with gr.Row():
|
| 63 |
instruction_panel = gr.Markdown()
|
tutor.py
CHANGED
|
@@ -18,7 +18,6 @@ class Tutor:
|
|
| 18 |
self.deserialize(context)
|
| 19 |
else:
|
| 20 |
self.memory = []
|
| 21 |
-
# self.system_prompt = system_prompt(instructions, starter_code)
|
| 22 |
self.instructions = instructions
|
| 23 |
self.starter_code = starter_code
|
| 24 |
self.memory.append(
|
|
|
|
| 18 |
self.deserialize(context)
|
| 19 |
else:
|
| 20 |
self.memory = []
|
|
|
|
| 21 |
self.instructions = instructions
|
| 22 |
self.starter_code = starter_code
|
| 23 |
self.memory.append(
|