Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -427,8 +427,8 @@ def generate_code_from_pseudo(pseudo_code, max_length, temperature, top_k, top_p
|
|
| 427 |
try:
|
| 428 |
# Calculate BLEU scores
|
| 429 |
bleu_1, bleu_2, bleu_3, bleu_4 = calculate_bleu_score(reference_code, primary_code)
|
| 430 |
-
|
| 431 |
-
|
| 432 |
ββββββββββββββββββββββββββββββββββββββββ
|
| 433 |
β’ BLEU-1 (Unigram): {bleu_1:.4f} ({bleu_1*100:.2f}%)
|
| 434 |
β’ BLEU-2 (Bigram): {bleu_2:.4f} ({bleu_2*100:.2f}%)
|
|
@@ -442,11 +442,11 @@ def generate_code_from_pseudo(pseudo_code, max_length, temperature, top_k, top_p
|
|
| 442 |
β’ BLEU 0.2-0.3: Fair match
|
| 443 |
β’ BLEU < 0.2: Poor match
|
| 444 |
"""
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
ββββββββββββββββββββββββββββββββββββββββ
|
| 451 |
β’ Length Ratio: {code_metrics['length_ratio']:.3f}
|
| 452 |
β’ Precision: {code_metrics['precision']:.4f} ({code_metrics['precision']*100:.2f}%)
|
|
@@ -477,18 +477,23 @@ def generate_code_from_pseudo(pseudo_code, max_length, temperature, top_k, top_p
|
|
| 477 |
|
| 478 |
# Format alternative sequences
|
| 479 |
alternatives = ""
|
| 480 |
-
if num_sequences > 1:
|
| 481 |
alternatives = "π Alternative Generations:\n" + "β"*50 + "\n\n"
|
| 482 |
for i, code in enumerate(generated_codes[1:], 2):
|
| 483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
|
| 485 |
-
# Add to history
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
|
|
|
| 492 |
|
| 493 |
return primary_code, metrics_output, bleu_output, alternatives
|
| 494 |
|
|
|
|
| 427 |
try:
|
| 428 |
# Calculate BLEU scores
|
| 429 |
bleu_1, bleu_2, bleu_3, bleu_4 = calculate_bleu_score(reference_code, primary_code)
|
| 430 |
+
|
| 431 |
+
bleu_output = f"""π BLEU Scores:
|
| 432 |
ββββββββββββββββββββββββββββββββββββββββ
|
| 433 |
β’ BLEU-1 (Unigram): {bleu_1:.4f} ({bleu_1*100:.2f}%)
|
| 434 |
β’ BLEU-2 (Bigram): {bleu_2:.4f} ({bleu_2*100:.2f}%)
|
|
|
|
| 442 |
β’ BLEU 0.2-0.3: Fair match
|
| 443 |
β’ BLEU < 0.2: Poor match
|
| 444 |
"""
|
| 445 |
+
|
| 446 |
+
# Calculate additional metrics
|
| 447 |
+
code_metrics = calculate_code_metrics(reference_code, primary_code)
|
| 448 |
+
|
| 449 |
+
metrics_output = f"""π Additional Metrics:
|
| 450 |
ββββββββββββββββββββββββββββββββββββββββ
|
| 451 |
β’ Length Ratio: {code_metrics['length_ratio']:.3f}
|
| 452 |
β’ Precision: {code_metrics['precision']:.4f} ({code_metrics['precision']*100:.2f}%)
|
|
|
|
| 477 |
|
| 478 |
# Format alternative sequences
|
| 479 |
alternatives = ""
|
| 480 |
+
if num_sequences > 1 and len(generated_codes) > 1:
|
| 481 |
alternatives = "π Alternative Generations:\n" + "β"*50 + "\n\n"
|
| 482 |
for i, code in enumerate(generated_codes[1:], 2):
|
| 483 |
+
# Skip error messages in alternatives
|
| 484 |
+
if not code.startswith('#'):
|
| 485 |
+
alternatives += f"Variation {i}:\n```python\n{code}\n```\n\n"
|
| 486 |
+
else:
|
| 487 |
+
alternatives += f"Variation {i}: {code}\n\n"
|
| 488 |
|
| 489 |
+
# Add to history (only if primary code is not an error message)
|
| 490 |
+
if not primary_code.startswith('#'):
|
| 491 |
+
generation_history.append({
|
| 492 |
+
'pseudo': pseudo_code,
|
| 493 |
+
'generated': primary_code,
|
| 494 |
+
'bleu_4': bleu_4 if reference_code and not primary_code.startswith('#') else None,
|
| 495 |
+
'time': generation_time
|
| 496 |
+
})
|
| 497 |
|
| 498 |
return primary_code, metrics_output, bleu_output, alternatives
|
| 499 |
|