Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,71 @@ from PIL import Image
|
|
| 8 |
from transformers import CLIPModel, CLIPProcessor
|
| 9 |
|
| 10 |
pn.extension(design="bootstrap", sizing_mode="stretch_width")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
ICON_URLS = {
|
| 13 |
"brand-github": "https://github.com/holoviz/panel",
|
|
|
|
| 8 |
from transformers import CLIPModel, CLIPProcessor
|
| 9 |
|
| 10 |
pn.extension(design="bootstrap", sizing_mode="stretch_width")
|
| 11 |
+
import panel as pn
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import os
|
| 14 |
+
import datetime
|
| 15 |
+
import io
|
| 16 |
+
|
| 17 |
+
from google_sheet import fetch_leaderboard
|
| 18 |
+
from google_drive import upload_to_drive
|
| 19 |
+
|
| 20 |
+
pn.extension()
|
| 21 |
+
|
| 22 |
+
# File upload widget
|
| 23 |
+
file_input = pn.widgets.FileInput(accept='.zip', multiple=False)
|
| 24 |
+
|
| 25 |
+
# Status message
|
| 26 |
+
status = pn.pane.Markdown("")
|
| 27 |
+
|
| 28 |
+
# Leaderboard display
|
| 29 |
+
leaderboard = pn.pane.DataFrame(pd.DataFrame(), width=600)
|
| 30 |
+
|
| 31 |
+
def submit_file(event):
|
| 32 |
+
if file_input.value is None:
|
| 33 |
+
status.object = "⚠️ Please upload a .zip file before submitting."
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
+
# Save uploaded file
|
| 37 |
+
timestamp = datetime.datetime.now().isoformat().replace(":", "_")
|
| 38 |
+
filename = f"{timestamp}_{file_input.filename}"
|
| 39 |
+
submission_path = os.path.join("submissions", filename)
|
| 40 |
+
os.makedirs("submissions", exist_ok=True)
|
| 41 |
+
with open(submission_path, "wb") as f:
|
| 42 |
+
f.write(file_input.value)
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
drive_file_id = upload_to_drive(submission_path, filename)
|
| 46 |
+
status.object = f"✅ Uploaded to Google Drive [File ID: {drive_file_id}]"
|
| 47 |
+
except Exception as e:
|
| 48 |
+
status.object = f"❌ Failed to upload to Google Drive: {e}"
|
| 49 |
+
|
| 50 |
+
# Update leaderboard
|
| 51 |
+
try:
|
| 52 |
+
df = fetch_leaderboard()
|
| 53 |
+
if not df.empty:
|
| 54 |
+
df_sorted = df.sort_values(by="score", ascending=False)
|
| 55 |
+
leaderboard.object = df_sorted
|
| 56 |
+
else:
|
| 57 |
+
leaderboard.object = pd.DataFrame()
|
| 58 |
+
except Exception as e:
|
| 59 |
+
status.object += f"\n⚠️ Could not load leaderboard: {e}"
|
| 60 |
+
|
| 61 |
+
submit_button = pn.widgets.Button(name="Submit", button_type="primary")
|
| 62 |
+
submit_button.on_click(submit_file)
|
| 63 |
+
|
| 64 |
+
# Layout
|
| 65 |
+
app = pn.Column(
|
| 66 |
+
"## 🏆 Hackathon Leaderboard",
|
| 67 |
+
file_input,
|
| 68 |
+
submit_button,
|
| 69 |
+
status,
|
| 70 |
+
"### Leaderboard",
|
| 71 |
+
leaderboard
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# app.servable()
|
| 75 |
+
|
| 76 |
|
| 77 |
ICON_URLS = {
|
| 78 |
"brand-github": "https://github.com/holoviz/panel",
|