Adding and testing explain solution
Browse files
app.py
CHANGED
@@ -159,6 +159,18 @@ def random_problem(token: str) -> Dict[str, Any]:
|
|
159 |
|
160 |
return {"problem": problem}
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
# Create Gradio interfaces
|
163 |
generate_interface = gr.Interface(
|
164 |
fn=generate_solution,
|
@@ -176,6 +188,14 @@ random_problem_interface = gr.Interface(
|
|
176 |
description="Provide a valid JWT token to get a random LeetCode problem."
|
177 |
)
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
demo = gr.TabbedInterface(
|
180 |
[generate_interface, explain_interface, random_problem_interface],
|
181 |
["Generate Solution", "Explain Solution", "Random Problem"]
|
|
|
159 |
|
160 |
return {"problem": problem}
|
161 |
|
162 |
+
def explain_solution(token: str) -> Dict[str, Any]:
|
163 |
+
if not verify_token(token):
|
164 |
+
return {"error": "Invalid token"}
|
165 |
+
|
166 |
+
if token not in user_data or not user_data[token].get("solution"):
|
167 |
+
return {"error": "No solution available to explain. Please generate a solution first."}
|
168 |
+
|
169 |
+
problem = user_data[token]["problem"]
|
170 |
+
solution = user_data[token]["solution"]
|
171 |
+
|
172 |
+
return generate_explanation(problem, solution, token)
|
173 |
+
|
174 |
# Create Gradio interfaces
|
175 |
generate_interface = gr.Interface(
|
176 |
fn=generate_solution,
|
|
|
188 |
description="Provide a valid JWT token to get a random LeetCode problem."
|
189 |
)
|
190 |
|
191 |
+
explain_interface = gr.Interface(
|
192 |
+
fn=explain_solution,
|
193 |
+
inputs=gr.Textbox(label="JWT Token"),
|
194 |
+
outputs=gr.JSON(),
|
195 |
+
title="Explain Solution API",
|
196 |
+
description="Provide a valid JWT token to get an explanation of the last generated solution."
|
197 |
+
)
|
198 |
+
|
199 |
demo = gr.TabbedInterface(
|
200 |
[generate_interface, explain_interface, random_problem_interface],
|
201 |
["Generate Solution", "Explain Solution", "Random Problem"]
|