CodeMode Agent commited on
Commit ·
bf36ea9
1
Parent(s): 4743590
Deploy CodeMode via Agent
Browse files- app.py +60 -4
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -332,7 +332,35 @@ def analyze_embeddings_baseline():
|
|
| 332 |
"topic": [m.get("file_name", "unknown") for m in data['metadatas']]
|
| 333 |
})
|
| 334 |
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
except Exception as e:
|
| 337 |
import traceback
|
| 338 |
traceback.print_exc()
|
|
@@ -374,7 +402,35 @@ def analyze_embeddings_finetuned():
|
|
| 374 |
"topic": [m.get("file_name", "unknown") for m in data['metadatas']]
|
| 375 |
})
|
| 376 |
|
| 377 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
except Exception as e:
|
| 379 |
import traceback
|
| 380 |
traceback.print_exc()
|
|
@@ -641,14 +697,14 @@ with gr.Blocks(theme=theme, css=css, title="CodeMode - Baseline vs Fine-tuned")
|
|
| 641 |
gr.Markdown("#### Baseline Model")
|
| 642 |
analyze_baseline_btn = gr.Button("Analyze Baseline Embeddings", variant="secondary")
|
| 643 |
baseline_metrics = gr.Textbox(label="Baseline Metrics")
|
| 644 |
-
baseline_plot = gr.
|
| 645 |
analyze_baseline_btn.click(analyze_embeddings_baseline, inputs=[], outputs=[baseline_metrics, baseline_plot])
|
| 646 |
|
| 647 |
with gr.Column():
|
| 648 |
gr.Markdown("#### Fine-tuned Model")
|
| 649 |
analyze_finetuned_btn = gr.Button("Analyze Fine-tuned Embeddings", variant="secondary")
|
| 650 |
finetuned_metrics = gr.Textbox(label="Fine-tuned Metrics")
|
| 651 |
-
finetuned_plot = gr.
|
| 652 |
analyze_finetuned_btn.click(analyze_embeddings_finetuned, inputs=[], outputs=[finetuned_metrics, finetuned_plot])
|
| 653 |
|
| 654 |
gr.Markdown("---")
|
|
|
|
| 332 |
"topic": [m.get("file_name", "unknown") for m in data['metadatas']]
|
| 333 |
})
|
| 334 |
|
| 335 |
+
import matplotlib.pyplot as plt
|
| 336 |
+
import io
|
| 337 |
+
from PIL import Image
|
| 338 |
+
|
| 339 |
+
# Create matplotlib figure with proper spacing
|
| 340 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
| 341 |
+
fig.subplots_adjust(top=0.92) # Add space for title
|
| 342 |
+
|
| 343 |
+
# Plot each file with different color
|
| 344 |
+
unique_topics = plot_df["topic"].unique()
|
| 345 |
+
for topic in unique_topics:
|
| 346 |
+
mask = plot_df["topic"] == topic
|
| 347 |
+
ax.scatter(plot_df[mask]["x"], plot_df[mask]["y"], label=topic, alpha=0.6, s=50)
|
| 348 |
+
|
| 349 |
+
ax.set_xlabel("PC1")
|
| 350 |
+
ax.set_ylabel("PC2")
|
| 351 |
+
ax.set_title("Baseline Semantic Space (PCA)", fontsize=14, pad=20)
|
| 352 |
+
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=8)
|
| 353 |
+
ax.grid(True, alpha=0.3)
|
| 354 |
+
plt.tight_layout()
|
| 355 |
+
|
| 356 |
+
# Convert to image for Gradio
|
| 357 |
+
buf = io.BytesIO()
|
| 358 |
+
plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
|
| 359 |
+
buf.seek(0)
|
| 360 |
+
img = Image.open(buf)
|
| 361 |
+
plt.close()
|
| 362 |
+
|
| 363 |
+
return metrics, img
|
| 364 |
except Exception as e:
|
| 365 |
import traceback
|
| 366 |
traceback.print_exc()
|
|
|
|
| 402 |
"topic": [m.get("file_name", "unknown") for m in data['metadatas']]
|
| 403 |
})
|
| 404 |
|
| 405 |
+
import matplotlib.pyplot as plt
|
| 406 |
+
import io
|
| 407 |
+
from PIL import Image
|
| 408 |
+
|
| 409 |
+
# Create matplotlib figure with proper spacing
|
| 410 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
| 411 |
+
fig.subplots_adjust(top=0.92) # Add space for title
|
| 412 |
+
|
| 413 |
+
# Plot each file with different color
|
| 414 |
+
unique_topics = plot_df["topic"].unique()
|
| 415 |
+
for topic in unique_topics:
|
| 416 |
+
mask = plot_df["topic"] == topic
|
| 417 |
+
ax.scatter(plot_df[mask]["x"], plot_df[mask]["y"], label=topic, alpha=0.6, s=50)
|
| 418 |
+
|
| 419 |
+
ax.set_xlabel("PC1")
|
| 420 |
+
ax.set_ylabel("PC2")
|
| 421 |
+
ax.set_title("Fine-tuned Semantic Space (PCA)", fontsize=14, pad=20)
|
| 422 |
+
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=8)
|
| 423 |
+
ax.grid(True, alpha=0.3)
|
| 424 |
+
plt.tight_layout()
|
| 425 |
+
|
| 426 |
+
# Convert to image for Gradio
|
| 427 |
+
buf = io.BytesIO()
|
| 428 |
+
plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
|
| 429 |
+
buf.seek(0)
|
| 430 |
+
img = Image.open(buf)
|
| 431 |
+
plt.close()
|
| 432 |
+
|
| 433 |
+
return metrics, img
|
| 434 |
except Exception as e:
|
| 435 |
import traceback
|
| 436 |
traceback.print_exc()
|
|
|
|
| 697 |
gr.Markdown("#### Baseline Model")
|
| 698 |
analyze_baseline_btn = gr.Button("Analyze Baseline Embeddings", variant="secondary")
|
| 699 |
baseline_metrics = gr.Textbox(label="Baseline Metrics")
|
| 700 |
+
baseline_plot = gr.Image(label="Baseline Semantic Space (PCA)")
|
| 701 |
analyze_baseline_btn.click(analyze_embeddings_baseline, inputs=[], outputs=[baseline_metrics, baseline_plot])
|
| 702 |
|
| 703 |
with gr.Column():
|
| 704 |
gr.Markdown("#### Fine-tuned Model")
|
| 705 |
analyze_finetuned_btn = gr.Button("Analyze Fine-tuned Embeddings", variant="secondary")
|
| 706 |
finetuned_metrics = gr.Textbox(label="Fine-tuned Metrics")
|
| 707 |
+
finetuned_plot = gr.Image(label="Fine-tuned Semantic Space (PCA)")
|
| 708 |
analyze_finetuned_btn.click(analyze_embeddings_finetuned, inputs=[], outputs=[finetuned_metrics, finetuned_plot])
|
| 709 |
|
| 710 |
gr.Markdown("---")
|
requirements.txt
CHANGED
|
@@ -11,3 +11,5 @@ beautifulsoup4>=4.11.0
|
|
| 11 |
huggingface_hub<1.0.0
|
| 12 |
tree-sitter>=0.20.0
|
| 13 |
tree-sitter-python>=0.20.0
|
|
|
|
|
|
|
|
|
| 11 |
huggingface_hub<1.0.0
|
| 12 |
tree-sitter>=0.20.0
|
| 13 |
tree-sitter-python>=0.20.0
|
| 14 |
+
matplotlib>=3.5.0
|
| 15 |
+
Pillow>=9.0.0
|