Spaces:
Running
Running
fixes
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ from datetime import datetime, timedelta
|
|
5 |
from collections import deque
|
6 |
import random
|
7 |
import logging
|
8 |
-
import tempfile
|
9 |
|
10 |
# Set up logging
|
11 |
logging.basicConfig(level=logging.DEBUG)
|
@@ -115,24 +114,26 @@ def generate_test(subject):
|
|
115 |
response_text = message.content[0].text
|
116 |
logger.debug("Successfully received response from Anthropic API")
|
117 |
|
118 |
-
# Create
|
119 |
-
|
120 |
-
|
121 |
-
f_questions.write(questions_latex)
|
122 |
-
questions_path = f_questions.name
|
123 |
-
|
124 |
-
with tempfile.NamedTemporaryFile(mode='w', suffix='.tex', delete=False) as f_full:
|
125 |
-
full_latex = create_latex_document(response_text, questions_only=False)
|
126 |
-
f_full.write(full_latex)
|
127 |
-
full_path = f_full.name
|
128 |
-
|
129 |
-
logger.debug("Successfully created temporary files")
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
except Exception as e:
|
138 |
logger.error(f"Error generating test: {str(e)}")
|
@@ -177,14 +178,8 @@ with gr.Blocks() as interface:
|
|
177 |
|
178 |
def generate_and_prepare_files(subject):
|
179 |
logger.debug("Starting test generation")
|
180 |
-
preview,
|
181 |
-
|
182 |
-
if questions_path and full_path:
|
183 |
-
logger.debug("Test generation successful, preparing files")
|
184 |
-
return preview, questions_path, full_path
|
185 |
-
else:
|
186 |
-
logger.error("Test generation failed")
|
187 |
-
return preview, None, None
|
188 |
|
189 |
generate_btn.click(
|
190 |
generate_and_prepare_files,
|
|
|
5 |
from collections import deque
|
6 |
import random
|
7 |
import logging
|
|
|
8 |
|
9 |
# Set up logging
|
10 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
114 |
response_text = message.content[0].text
|
115 |
logger.debug("Successfully received response from Anthropic API")
|
116 |
|
117 |
+
# Create LaTeX content
|
118 |
+
questions_latex = create_latex_document(response_text, questions_only=True)
|
119 |
+
full_latex = create_latex_document(response_text, questions_only=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
+
# Create file-like objects for Gradio
|
122 |
+
questions_file = {
|
123 |
+
"name": "questions.tex",
|
124 |
+
"content": questions_latex.encode('utf-8'),
|
125 |
+
"mime_type": "text/plain"
|
126 |
+
}
|
127 |
+
|
128 |
+
full_file = {
|
129 |
+
"name": "full_test.tex",
|
130 |
+
"content": full_latex.encode('utf-8'),
|
131 |
+
"mime_type": "text/plain"
|
132 |
+
}
|
133 |
+
|
134 |
+
logger.debug("Successfully created file objects")
|
135 |
+
|
136 |
+
return response_text, questions_file, full_file
|
137 |
|
138 |
except Exception as e:
|
139 |
logger.error(f"Error generating test: {str(e)}")
|
|
|
178 |
|
179 |
def generate_and_prepare_files(subject):
|
180 |
logger.debug("Starting test generation")
|
181 |
+
preview, questions_file_obj, full_file_obj = generate_test(subject)
|
182 |
+
return preview, questions_file_obj, full_file_obj
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
generate_btn.click(
|
185 |
generate_and_prepare_files,
|