burtenshaw
commited on
Commit
·
3a3fcba
1
Parent(s):
ac8a8fb
add explanation
Browse files
app.py
CHANGED
|
@@ -9,9 +9,7 @@ import black # Add black import
|
|
| 9 |
|
| 10 |
# Initialize the inference client
|
| 11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 12 |
-
HF_API_URL = os.getenv(
|
| 13 |
-
"HF_API_URL", "https://sm6g3bin692qbz80.us-east-1.aws.endpoints.huggingface.cloud"
|
| 14 |
-
)
|
| 15 |
client = InferenceClient(api_key=HF_TOKEN)
|
| 16 |
|
| 17 |
# Load questions from Hugging Face dataset
|
|
@@ -97,7 +95,7 @@ def check_code(
|
|
| 97 |
|
| 98 |
# Add the explanation to the status text with emoji
|
| 99 |
explanation = response.split("\n", 1)[1] if "\n" in response else ""
|
| 100 |
-
status = "✅ Correct!" if is_correct else "❌ Incorrect!"
|
| 101 |
gr.Info(f"{status}\n\n{explanation}")
|
| 102 |
|
| 103 |
return is_correct
|
|
@@ -106,7 +104,7 @@ def check_code(
|
|
| 106 |
gr.Warning(f"Error checking code: {str(e)}")
|
| 107 |
# Fall back to simple string comparison if LLM fails
|
| 108 |
is_correct = formatted_user_code.strip() == formatted_solution.strip()
|
| 109 |
-
status = "✅ Correct!" if is_correct else "❌ Incorrect!"
|
| 110 |
gr.Info(f"{status} (Fallback comparison)")
|
| 111 |
return is_correct
|
| 112 |
|
|
|
|
| 9 |
|
| 10 |
# Initialize the inference client
|
| 11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 12 |
+
HF_API_URL = os.getenv("HF_API_URL", "Qwen/Qwen2.5-Coder-32B-Instruct")
|
|
|
|
|
|
|
| 13 |
client = InferenceClient(api_key=HF_TOKEN)
|
| 14 |
|
| 15 |
# Load questions from Hugging Face dataset
|
|
|
|
| 95 |
|
| 96 |
# Add the explanation to the status text with emoji
|
| 97 |
explanation = response.split("\n", 1)[1] if "\n" in response else ""
|
| 98 |
+
status = "✅ Correct!" if is_correct else "❌ Incorrect!" + f"\n\n{explanation}"
|
| 99 |
gr.Info(f"{status}\n\n{explanation}")
|
| 100 |
|
| 101 |
return is_correct
|
|
|
|
| 104 |
gr.Warning(f"Error checking code: {str(e)}")
|
| 105 |
# Fall back to simple string comparison if LLM fails
|
| 106 |
is_correct = formatted_user_code.strip() == formatted_solution.strip()
|
| 107 |
+
status = "✅ Correct!" if is_correct else "❌ Incorrect!" + f"\n\n{explanation}"
|
| 108 |
gr.Info(f"{status} (Fallback comparison)")
|
| 109 |
return is_correct
|
| 110 |
|