File size: 3,892 Bytes
712bb5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from pydantic import BaseModel
import os

app = FastAPI(
    title="Sheikh LLM API",
    description="A powerful LLM API deployed on Hugging Face Spaces",
    version="1.0.0"
)

class ChatRequest(BaseModel):
    message: str
    max_tokens: int = 100

class ChatResponse(BaseModel):
    response: str
    status: str

@app.get("/", response_class=HTMLResponse)
def home():    return """
    <!DOCTYPE html>
    <html>
    <head>
        <title>Sheikh LLM</title>
        <style>
            body { 
                font-family: Arial, sans-serif; 
                margin: 0; 
                padding: 20px; 
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                color: white;
            }
            .container { 
                max-width: 800px; 
                margin: 0 auto; 
                background: rgba(255,255,255,0.1);
                padding: 30px;
                border-radius: 15px;
                backdrop-filter: blur(10px);
            }
            .header { 
                text-align: center; 
                margin-bottom: 30px;
            }
            .endpoints { 
                background: rgba(255,255,255,0.2); 
                padding: 20px; 
                border-radius: 10px; 
                margin: 20px 0; 
            }
            a { color: #ffd700; text-decoration: none; }
            a:hover { text-decoration: underline; }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="header">
                <h1>πŸš€ Sheikh LLM Space</h1>
                <p>Welcome to your automated Hugging Face Space!</p>
            </div>
            
            <div class="endpoints">
                <h2>πŸ“‘ API Endpoints:</h2>
                <ul>
                    <li><a href="/health" target="_blank">GET /health</a> - Health check</li>
                    <li><a href="/api/status" target="_blank">GET /api/status</a> - API status</li>
                    <li><a href="/docs" target="_blank">GET /docs</a> - Interactive API documentation</li>
                </ul>
            </div>

            <div class="endpoints">
                <h2>⚑ Quick Test:</h2>
                <p>Try this curl command to test the API:</p>
                <code style="background: black; padding: 10px; display: block; border-radius: 5px;">
                curl -X GET "https://recentcoders-sheikh-llm.hf.space/health"
                </code>
            </div>
        </div>
    </body>
    </html>
    """

@app.get("/health")
async def health_check():
    return JSONResponse({
        "status": "healthy", 
        "service": "sheikh-llm",
        "version": "1.0.0",
        "environment": "production"
    })

@app.get("/api/status")
async def api_status():
    return {
        "service": "sheikh-llm",
        "version": "1.0.0",
        "status": "running",
        "endpoints": [
            {"path": "/", "method": "GET", "description": "Homepage"},
            {"path": "/health", "method": "GET", "description": "Health check"},
            {"path": "/api/status", "method": "GET", "description": "API status"},
            {"path": "/docs", "method": "GET", "description": "Swagger UI"}
        ]
    }

@app.post("/api/chat", response_model=ChatResponse)
async def chat_endpoint(request: ChatRequest):
    """Simple chat endpoint that echoes the message"""
    if not request.message.strip():
        raise HTTPException(status_code=400, detail="Message cannot be empty")
    
    response_text = f"Received your message: '{request.message}'. This is from Sheikh LLM API!"
    
    return ChatResponse(
        response=response_text,
        status="success"
    )

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)