Upload 3 files
Browse files- app.py +18 -15
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -28,7 +28,7 @@ EMBEDDING_MODEL = os.getenv(
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
-
def upload_textbook(pdf_path
|
| 32 |
if not pdf_path:
|
| 33 |
return "Choose a PDF first.", {}, gr.update()
|
| 34 |
|
|
@@ -63,7 +63,7 @@ def upload_textbook(pdf_path: str | None) -> tuple[str, dict[str, Any], Any]:
|
|
| 63 |
return f"Could not read uploaded PDF: {exc}", {}, gr.update()
|
| 64 |
|
| 65 |
|
| 66 |
-
def upload_textbook_locally(pdf_path
|
| 67 |
try:
|
| 68 |
extracted = extract_pdf_text(pdf_path)
|
| 69 |
chunks = chunk_text(extracted["text"])
|
|
@@ -94,11 +94,11 @@ def upload_textbook_locally(pdf_path: str) -> tuple[str, dict[str, Any], Any]:
|
|
| 94 |
|
| 95 |
|
| 96 |
def ask_tutor(
|
| 97 |
-
question
|
| 98 |
-
student_id
|
| 99 |
-
textbook_context
|
| 100 |
-
textbook_state
|
| 101 |
-
)
|
| 102 |
question = question.strip()
|
| 103 |
student_id = (student_id or "hf-space-demo").strip()
|
| 104 |
textbook_context = textbook_context.strip()
|
|
@@ -185,12 +185,12 @@ def format_backend_response(
|
|
| 185 |
|
| 186 |
|
| 187 |
def grade_quiz(
|
| 188 |
-
answer_1
|
| 189 |
-
answer_2
|
| 190 |
-
answer_3
|
| 191 |
-
student_id
|
| 192 |
-
quiz_state
|
| 193 |
-
)
|
| 194 |
quiz_state = quiz_state or {}
|
| 195 |
quiz_id = quiz_state.get("quiz_id")
|
| 196 |
|
|
@@ -269,7 +269,7 @@ def normalize_answer(answer: str) -> str:
|
|
| 269 |
)
|
| 270 |
|
| 271 |
|
| 272 |
-
def parent_summary(student_id
|
| 273 |
if not BACKEND_URL:
|
| 274 |
return (
|
| 275 |
"Parent/teacher summary\n\n"
|
|
@@ -904,4 +904,7 @@ with gr.Blocks(title=APP_NAME, theme=gr.themes.Soft()) as demo:
|
|
| 904 |
|
| 905 |
|
| 906 |
if __name__ == "__main__":
|
| 907 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
+
def upload_textbook(pdf_path):
|
| 32 |
if not pdf_path:
|
| 33 |
return "Choose a PDF first.", {}, gr.update()
|
| 34 |
|
|
|
|
| 63 |
return f"Could not read uploaded PDF: {exc}", {}, gr.update()
|
| 64 |
|
| 65 |
|
| 66 |
+
def upload_textbook_locally(pdf_path):
|
| 67 |
try:
|
| 68 |
extracted = extract_pdf_text(pdf_path)
|
| 69 |
chunks = chunk_text(extracted["text"])
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
def ask_tutor(
|
| 97 |
+
question,
|
| 98 |
+
student_id,
|
| 99 |
+
textbook_context,
|
| 100 |
+
textbook_state,
|
| 101 |
+
):
|
| 102 |
question = question.strip()
|
| 103 |
student_id = (student_id or "hf-space-demo").strip()
|
| 104 |
textbook_context = textbook_context.strip()
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
def grade_quiz(
|
| 188 |
+
answer_1,
|
| 189 |
+
answer_2,
|
| 190 |
+
answer_3,
|
| 191 |
+
student_id,
|
| 192 |
+
quiz_state,
|
| 193 |
+
):
|
| 194 |
quiz_state = quiz_state or {}
|
| 195 |
quiz_id = quiz_state.get("quiz_id")
|
| 196 |
|
|
|
|
| 269 |
)
|
| 270 |
|
| 271 |
|
| 272 |
+
def parent_summary(student_id):
|
| 273 |
if not BACKEND_URL:
|
| 274 |
return (
|
| 275 |
"Parent/teacher summary\n\n"
|
|
|
|
| 904 |
|
| 905 |
|
| 906 |
if __name__ == "__main__":
|
| 907 |
+
demo.launch(
|
| 908 |
+
server_name="0.0.0.0",
|
| 909 |
+
server_port=int(os.getenv("PORT", "7860")),
|
| 910 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio
|
| 2 |
python-dotenv>=1.0.0
|
| 3 |
requests>=2.31.0
|
| 4 |
numpy>=1.26.0
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
python-dotenv>=1.0.0
|
| 3 |
requests>=2.31.0
|
| 4 |
numpy>=1.26.0
|