sheikh-llm / app.py
root
Initial commit: FastAPI application with health endpoints
712bb5f
raw
history blame
3.89 kB
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)