Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitignore +2 -0
- Dockerfile +16 -0
- app/__init__.py +0 -0
- app/main.py +14 -0
- app/routers/calculator.py +37 -0
- app/routers/help.py +19 -0
- app/routers/random_number_generator.py +36 -0
- requirements.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# prompts file
|
| 2 |
+
prompt.txt
|
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.11
|
| 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.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/__init__.py
ADDED
|
File without changes
|
app/main.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
# Import all your routers
|
| 3 |
+
from app.routers import random_number_generator, help, calculator # <-- Import the new router
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Include all routers
|
| 8 |
+
app.include_router(random_number_generator.router)
|
| 9 |
+
app.include_router(help.router)
|
| 10 |
+
app.include_router(calculator.router) # <-- Include the new router
|
| 11 |
+
|
| 12 |
+
@app.get("/")
|
| 13 |
+
def greet_json():
|
| 14 |
+
return {"Hello": "World!", "message": "Go to /docs to see all available endpoints!"}
|
app/routers/calculator.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
|
| 3 |
+
# Create the router for calculator endpoints
|
| 4 |
+
router = APIRouter(
|
| 5 |
+
prefix="/calculate",
|
| 6 |
+
tags=["Calculator"]
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
@router.get("/add")
|
| 10 |
+
def add_numbers(a: float, b: float):
|
| 11 |
+
"""
|
| 12 |
+
Adds two numbers, 'a' and 'b'.
|
| 13 |
+
|
| 14 |
+
Query parameters: a (float), b (float)
|
| 15 |
+
"""
|
| 16 |
+
result = a + b
|
| 17 |
+
return {
|
| 18 |
+
"operation": "addition",
|
| 19 |
+
"a": a,
|
| 20 |
+
"b": b,
|
| 21 |
+
"result": result
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
@router.get("/subtract")
|
| 25 |
+
def subtract_numbers(a: float, b: float):
|
| 26 |
+
"""
|
| 27 |
+
Subtracts number 'b' from number 'a' (a - b).
|
| 28 |
+
|
| 29 |
+
Query parameters: a (float), b (float)
|
| 30 |
+
"""
|
| 31 |
+
result = a - b
|
| 32 |
+
return {
|
| 33 |
+
"operation": "subtraction",
|
| 34 |
+
"a": a,
|
| 35 |
+
"b": b,
|
| 36 |
+
"result": result
|
| 37 |
+
}
|
app/routers/help.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
|
| 3 |
+
# Create the router for help/info endpoints
|
| 4 |
+
router = APIRouter(
|
| 5 |
+
prefix="/help",
|
| 6 |
+
tags=["Information"]
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
@router.get("/")
|
| 10 |
+
def get_api_info():
|
| 11 |
+
"""
|
| 12 |
+
Returns general information about the API and available endpoints.
|
| 13 |
+
"""
|
| 14 |
+
return {
|
| 15 |
+
"api_name": "My Awesome FastAPI",
|
| 16 |
+
"version": "1.0",
|
| 17 |
+
"available_sections": ["/random", "/help"],
|
| 18 |
+
"message": "Use the /docs endpoint for interactive API documentation."
|
| 19 |
+
}
|
app/routers/random_number_generator.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
from fastapi import APIRouter
|
| 3 |
+
|
| 4 |
+
# Create a new APIRouter instance
|
| 5 |
+
# We'll set a prefix so all paths in this router start with /random
|
| 6 |
+
router = APIRouter(
|
| 7 |
+
prefix="/random",
|
| 8 |
+
tags=["Random Numbers"] # Optional: helps organize documentation (Swagger UI)
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
@router.get("/integer")
|
| 12 |
+
def get_random_integer(min_val: int = 1, max_val: int = 100):
|
| 13 |
+
"""
|
| 14 |
+
Generate a random integer between min_val (inclusive) and max_val (inclusive).
|
| 15 |
+
|
| 16 |
+
Defaults to a number between 1 and 100.
|
| 17 |
+
"""
|
| 18 |
+
if min_val > max_val:
|
| 19 |
+
# Swap if min is greater than max to ensure the range is valid
|
| 20 |
+
min_val, max_val = max_val, min_val
|
| 21 |
+
|
| 22 |
+
random_int = random.randint(min_val, max_val)
|
| 23 |
+
|
| 24 |
+
return {
|
| 25 |
+
"min_value": min_val,
|
| 26 |
+
"max_value": max_val,
|
| 27 |
+
"random_number": random_int
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
@router.get("/float")
|
| 31 |
+
def get_random_float():
|
| 32 |
+
"""
|
| 33 |
+
Generate a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive).
|
| 34 |
+
"""
|
| 35 |
+
random_float = random.random()
|
| 36 |
+
return {"random_float": random_float}
|
requirements.txt
ADDED
|
File without changes
|