amit0987 commited on
Commit
bbd2266
·
1 Parent(s): 4929f3f

Create Dockerfile

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. app.py +20 -3
  3. requirements.txt +3 -1
  4. test.py +23 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,7 +1,24 @@
1
  from fastapi import FastAPI
2
 
3
- app = FastAPI()
4
 
5
  @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
 
3
+ app = FastAPI() # This must be global and named exactly "app"
4
 
5
  @app.get("/")
6
+ def read_root():
7
+ return {"message": "Hello from song_json_api_hf!"}
8
+
9
+ @app.get("/songs")
10
+ def get_songs():
11
+ return [
12
+ {
13
+ "title": "Sample Song",
14
+ "artist": "Artist A",
15
+ "url": "https://example.com/song1.mp3",
16
+ "album_art": "https://example.com/art1.jpg"
17
+ },
18
+ {
19
+ "title": "Another Song",
20
+ "artist": "Artist B",
21
+ "url": "https://example.com/song2.mp3",
22
+ "album_art": "https://example.com/art2.jpg"
23
+ }
24
+ ]
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
- fastapi
2
  uvicorn[standard]
 
 
 
1
+ fastapi~=0.115.12
2
  uvicorn[standard]
3
+
4
+ requests~=2.32.3
test.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ BASE_URL = "https://amit0987-song-json-api-hf.hf.space" # Replace with your actual Space URL
4
+
5
+ def safe_print_json(response, label):
6
+ print(f"{label} -> {response.status_code}")
7
+ try:
8
+ print(response.json())
9
+ except Exception:
10
+ print("Response is not JSON:")
11
+ print(response.text)
12
+
13
+ def test_root():
14
+ response = requests.get(f"{BASE_URL}/")
15
+ safe_print_json(response, "GET /")
16
+
17
+ def test_songs():
18
+ response = requests.get(f"{BASE_URL}/songs")
19
+ safe_print_json(response, "GET /songs")
20
+
21
+ if __name__ == "__main__":
22
+ test_root()
23
+ test_songs()