Enhance app.py to validate and format SPACE_ID at startup, ensuring proper username/repo structure; update requirements.txt to add pandas dependency.
Browse files- app.py +15 -1
- requirements.txt +2 -1
- result_dataset.py +48 -0
app.py
CHANGED
@@ -283,7 +283,21 @@ if __name__ == "__main__":
|
|
283 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
284 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
285 |
space_host_startup = os.getenv("SPACE_HOST")
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
if space_host_startup:
|
289 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
|
|
283 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
284 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
285 |
space_host_startup = os.getenv("SPACE_HOST")
|
286 |
+
space_id_raw = os.getenv("SPACE_ID", "")
|
287 |
+
|
288 |
+
# Ensure proper SPACE_ID format with username/repo
|
289 |
+
if not space_id_raw:
|
290 |
+
# Default if completely missing
|
291 |
+
space_id_startup = "martinsu/Final_Assignment_Template"
|
292 |
+
elif "/" in space_id_raw and not space_id_raw.startswith("/"):
|
293 |
+
# Already has proper username/repo format
|
294 |
+
space_id_startup = space_id_raw
|
295 |
+
elif space_id_raw.startswith("/"):
|
296 |
+
# Has a leading slash but missing username
|
297 |
+
space_id_startup = f"martinsu{space_id_raw}"
|
298 |
+
else:
|
299 |
+
# Just repo name without username
|
300 |
+
space_id_startup = f"martinsu/{space_id_raw}"
|
301 |
|
302 |
if space_host_startup:
|
303 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
requirements.txt
CHANGED
@@ -10,4 +10,5 @@ daytona_sdk
|
|
10 |
yt_dlp
|
11 |
tavily-python
|
12 |
langfuse
|
13 |
-
langchain
|
|
|
|
10 |
yt_dlp
|
11 |
tavily-python
|
12 |
langfuse
|
13 |
+
langchain
|
14 |
+
pandas
|
result_dataset.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
import duckdb
|
3 |
+
|
4 |
+
# Login using e.g. `huggingface-cli login` to access this dataset
|
5 |
+
ds = load_dataset("agents-course/unit4-students-scores")
|
6 |
+
|
7 |
+
# Convert the dataset to a Pandas DataFrame
|
8 |
+
df = ds["train"].to_pandas()
|
9 |
+
|
10 |
+
# Initialize DuckDB connection
|
11 |
+
con = duckdb.connect(":memory:")
|
12 |
+
|
13 |
+
# Register the DataFrame as a table
|
14 |
+
con.register("train", df)
|
15 |
+
|
16 |
+
# Example SQL query: Get average score by subject
|
17 |
+
query = """
|
18 |
+
WITH FilteredTrains AS (
|
19 |
+
SELECT *
|
20 |
+
FROM train
|
21 |
+
WHERE (code LIKE '%' || username || '%') or username = 'martinsu'
|
22 |
+
),
|
23 |
+
RankedTrains AS (
|
24 |
+
SELECT
|
25 |
+
code,
|
26 |
+
username,
|
27 |
+
score,
|
28 |
+
RANK() OVER (ORDER BY score DESC) AS rank
|
29 |
+
FROM
|
30 |
+
FilteredTrains
|
31 |
+
)
|
32 |
+
SELECT
|
33 |
+
rank
|
34 |
+
FROM
|
35 |
+
RankedTrains
|
36 |
+
WHERE
|
37 |
+
username = 'martinsu';
|
38 |
+
"""
|
39 |
+
result = con.execute(query).fetchdf()
|
40 |
+
print(result)
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|