Speedofmastery commited on
Commit
31b0744
·
verified ·
1 Parent(s): 70f6c0d

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +36 -0
  2. README.md +109 -10
  3. main.py +125 -0
  4. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use NVIDIA CUDA base image for GPU support
2
+ FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Install Python 3.10 and system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ python3.10 \
10
+ python3-pip \
11
+ python3.10-dev \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Set Python 3.10 as default
15
+ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
16
+ RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
17
+
18
+ # Upgrade pip
19
+ RUN pip install --no-cache-dir --upgrade pip
20
+
21
+ # Copy requirements and install Python dependencies
22
+ COPY requirements.txt .
23
+ RUN pip install --no-cache-dir -r requirements.txt
24
+
25
+ # Copy application code
26
+ COPY main.py .
27
+
28
+ # Expose port 7860 (HuggingFace Spaces default)
29
+ EXPOSE 7860
30
+
31
+ # Set environment variables
32
+ ENV PYTHONUNBUFFERED=1
33
+ ENV PORT=7860
34
+
35
+ # Run the FastAPI app with uvicorn
36
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
README.md CHANGED
@@ -1,10 +1,109 @@
1
- ---
2
- title: Yyuujhu
3
- emoji: 📚
4
- colorFrom: gray
5
- colorTo: pink
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FastAPI NVIDIA A10G
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ license: apache-2.0
9
+ suggested_hardware: a10g-large
10
+ suggested_storage: large
11
+ ---
12
+
13
+ # FastAPI Service with NVIDIA A10G Large GPU
14
+
15
+ High-performance FastAPI service running on NVIDIA A10G Large GPU (24GB VRAM).
16
+
17
+ ## 🚀 Features
18
+
19
+ - **FastAPI Framework**: Modern, fast web framework for building APIs
20
+ - **Uvicorn Server**: Lightning-fast ASGI server with uvicorn[standard]
21
+ - **GPU Acceleration**: NVIDIA A10G Large (24GB VRAM, 24 vCPU, 96GB RAM)
22
+ - **Docker SDK**: Containerized deployment for reliability
23
+ - **PyTorch Support**: Full CUDA support for ML workloads
24
+ - **Auto-scaling**: Optimized for high-performance workloads
25
+
26
+ ## 📊 Hardware Specs
27
+
28
+ - **GPU**: NVIDIA A10G Large (24GB VRAM)
29
+ - **CPU**: 24 vCPUs
30
+ - **RAM**: 96GB
31
+ - **Storage**: Large (100GB)
32
+ - **Cost**: ~$3.15/hour
33
+
34
+ ## 🔗 API Endpoints
35
+
36
+ ### Root
37
+ ```
38
+ GET /
39
+ ```
40
+ Returns API information and available endpoints.
41
+
42
+ ### Health Check
43
+ ```
44
+ GET /health
45
+ ```
46
+ Returns service health status and GPU availability.
47
+
48
+ ### GPU Information
49
+ ```
50
+ GET /gpu-info
51
+ ```
52
+ Returns detailed GPU specifications and memory information.
53
+
54
+ ### Process Text
55
+ ```
56
+ POST /process
57
+ Content-Type: application/json
58
+
59
+ {
60
+ "text": "Your text here",
61
+ "max_length": 100
62
+ }
63
+ ```
64
+ Example text processing endpoint.
65
+
66
+ ## 🛠️ API Documentation
67
+
68
+ Interactive API documentation available at:
69
+ - Swagger UI: `/docs`
70
+ - ReDoc: `/redoc`
71
+
72
+ ## 🔧 Configuration
73
+
74
+ The service runs on port 7860 (HuggingFace Spaces default) with:
75
+ - Single worker process for GPU efficiency
76
+ - CORS enabled for cross-origin requests
77
+ - Automatic GPU detection and utilization
78
+
79
+ ## 📦 Dependencies
80
+
81
+ - FastAPI 0.104.1
82
+ - Uvicorn[standard] 0.24.0
83
+ - PyTorch 2.1.0 (CUDA support)
84
+ - Pydantic 2.5.0
85
+
86
+ ## 🚀 Usage
87
+
88
+ ```python
89
+ import requests
90
+
91
+ # Health check
92
+ response = requests.get("https://huggingface.co/spaces/Speedofmastery/yyuujhu")
93
+ print(response.json())
94
+
95
+ # GPU info
96
+ gpu_info = requests.get("https://huggingface.co/spaces/Speedofmastery/yyuujhu/gpu-info")
97
+ print(gpu_info.json())
98
+
99
+ # Process text
100
+ result = requests.post(
101
+ "https://huggingface.co/spaces/Speedofmastery/yyuujhu/process",
102
+ json={"text": "Hello World", "max_length": 100}
103
+ )
104
+ print(result.json())
105
+ ```
106
+
107
+ ## 📝 License
108
+
109
+ Apache 2.0
main.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ import uvicorn
5
+ import torch
6
+ import os
7
+
8
+ # GPU Verification on startup
9
+ print("=" * 50)
10
+ print("🚀 OpenManus FastAPI - GPU Verification")
11
+ print("=" * 50)
12
+ print(f"Is CUDA available: {torch.cuda.is_available()}")
13
+ if torch.cuda.is_available():
14
+ print(f"CUDA device count: {torch.cuda.device_count()}")
15
+ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
16
+ print(f"CUDA version: {torch.version.cuda}")
17
+ print(f"PyTorch version: {torch.__version__}")
18
+ else:
19
+ print("⚠️ WARNING: CUDA not available - running on CPU")
20
+ print("=" * 50)
21
+
22
+ app = FastAPI(
23
+ title="OpenManus FastAPI",
24
+ description="High-performance FastAPI service with NVIDIA A10G GPU support",
25
+ version="1.0.0",
26
+ )
27
+
28
+ # CORS middleware
29
+ app.add_middleware(
30
+ CORSMiddleware,
31
+ allow_origins=["*"],
32
+ allow_credentials=True,
33
+ allow_methods=["*"],
34
+ allow_headers=["*"],
35
+ )
36
+
37
+
38
+ # Request models
39
+ class TextRequest(BaseModel):
40
+ text: str
41
+ max_length: int = 100
42
+
43
+
44
+ class HealthResponse(BaseModel):
45
+ status: str
46
+ gpu_available: bool
47
+ cuda_devices: int
48
+ device_name: str = None
49
+
50
+
51
+ @app.get("/", response_model=dict)
52
+ async def root():
53
+ """Root endpoint with API information"""
54
+ return {
55
+ "message": "OpenManus FastAPI Service",
56
+ "version": "1.0.0",
57
+ "endpoints": {"health": "/health", "gpu_info": "/gpu-info", "docs": "/docs"},
58
+ }
59
+
60
+
61
+ @app.get("/health", response_model=HealthResponse)
62
+ async def health_check():
63
+ """Health check endpoint with GPU status"""
64
+ gpu_available = torch.cuda.is_available()
65
+ cuda_devices = torch.cuda.device_count() if gpu_available else 0
66
+ device_name = (
67
+ torch.cuda.get_device_name(0) if gpu_available and cuda_devices > 0 else None
68
+ )
69
+
70
+ return HealthResponse(
71
+ status="healthy",
72
+ gpu_available=gpu_available,
73
+ cuda_devices=cuda_devices,
74
+ device_name=device_name,
75
+ )
76
+
77
+
78
+ @app.get("/gpu-info")
79
+ async def gpu_info():
80
+ """Detailed GPU information"""
81
+ if not torch.cuda.is_available():
82
+ return {"error": "CUDA not available"}
83
+
84
+ info = {
85
+ "cuda_available": True,
86
+ "device_count": torch.cuda.device_count(),
87
+ "devices": [],
88
+ }
89
+
90
+ for i in range(torch.cuda.device_count()):
91
+ device_props = torch.cuda.get_device_properties(i)
92
+ info["devices"].append(
93
+ {
94
+ "id": i,
95
+ "name": torch.cuda.get_device_name(i),
96
+ "total_memory_gb": round(device_props.total_memory / 1024**3, 2),
97
+ "major": device_props.major,
98
+ "minor": device_props.minor,
99
+ "multi_processor_count": device_props.multi_processor_count,
100
+ }
101
+ )
102
+
103
+ return info
104
+
105
+
106
+ @app.post("/process")
107
+ async def process_text(request: TextRequest):
108
+ """Example endpoint for text processing"""
109
+ try:
110
+ # Example processing logic
111
+ result = {
112
+ "input": request.text,
113
+ "length": len(request.text),
114
+ "max_length": request.max_length,
115
+ "processed": request.text.upper(), # Simple transformation
116
+ "gpu_used": torch.cuda.is_available(),
117
+ }
118
+ return result
119
+ except Exception as e:
120
+ raise HTTPException(status_code=500, detail=str(e))
121
+
122
+
123
+ if __name__ == "__main__":
124
+ port = int(os.environ.get("PORT", 7860))
125
+ uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False, workers=1)
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn[standard]==0.24.0
3
+ pydantic==2.5.0
4
+ python-multipart==0.0.6
5
+ huggingface-hub>=0.20.0
6
+ --extra-index-url https://download.pytorch.org/whl/cu118
7
+ torch==2.1.0+cu118
8
+ torchaudio==2.1.0+cu118
9
+ torchvision==0.16.0+cu118