Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
import random
|
| 4 |
from datetime import datetime
|
| 5 |
import platform
|
| 6 |
|
| 7 |
app = FastAPI(
|
| 8 |
-
title="
|
| 9 |
description="A seriously cool API with multiple endpoints",
|
| 10 |
version="2.0.0"
|
| 11 |
)
|
| 12 |
|
| 13 |
-
# Cool facts database
|
| 14 |
COOL_FACTS = [
|
| 15 |
"Honey never spoils. Archaeologists have found 3000-year-old honey in Egyptian tombs that's still edible.",
|
| 16 |
"A group of flamingos is called a 'flamboyance'.",
|
|
@@ -30,105 +28,56 @@ MOTIVATIONAL_QUOTES = [
|
|
| 30 |
"Believe you can and you're halfway there. - Theodore Roosevelt"
|
| 31 |
]
|
| 32 |
|
| 33 |
-
@app.get("/"
|
| 34 |
async def root():
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
.container {
|
| 49 |
-
background: rgba(0,0,0,0.3);
|
| 50 |
-
border-radius: 20px;
|
| 51 |
-
padding: 40px;
|
| 52 |
-
max-width: 800px;
|
| 53 |
-
margin: 0 auto;
|
| 54 |
-
backdrop-filter: blur(10px);
|
| 55 |
-
}
|
| 56 |
-
h1 { font-size: 3em; margin-bottom: 20px; }
|
| 57 |
-
.endpoint {
|
| 58 |
-
background: rgba(255,255,255,0.1);
|
| 59 |
-
padding: 15px;
|
| 60 |
-
margin: 10px 0;
|
| 61 |
-
border-radius: 10px;
|
| 62 |
-
text-align: left;
|
| 63 |
-
}
|
| 64 |
-
a { color: #ffd700; text-decoration: none; font-weight: bold; }
|
| 65 |
-
a:hover { text-decoration: underline; }
|
| 66 |
-
</style>
|
| 67 |
-
</head>
|
| 68 |
-
<body>
|
| 69 |
-
<div class="""container">
|
| 70 |
-
<h1>🚀 The-Chef's Epic API 🚀</h1>
|
| 71 |
-
<p>Welcome to the coolest API on Hugging Face Spaces!</p>
|
| 72 |
-
<h2>📡 Available Endpoints:</h2>
|
| 73 |
-
<div class="endpoint">
|
| 74 |
-
<strong>GET <a href="/status">/status</a></strong> - System status & info
|
| 75 |
-
</div>
|
| 76 |
-
<div class="endpoint">
|
| 77 |
-
<strong>GET <a href="/random-fact">/random-fact</a></strong> - Get a random cool fact
|
| 78 |
-
</div>
|
| 79 |
-
<div class="endpoint">
|
| 80 |
-
<strong>GET <a href="/motivate">/motivate</a></strong> - Get motivated!
|
| 81 |
-
</div>
|
| 82 |
-
<div class="endpoint">
|
| 83 |
-
<strong>GET <a href="/time">/time</a></strong> - Current server time
|
| 84 |
-
</div>
|
| 85 |
-
<div class="endpoint">
|
| 86 |
-
<strong>GET <a href="/docs">/docs</a></strong> - Interactive API documentation
|
| 87 |
-
</div>
|
| 88 |
-
</div>
|
| 89 |
-
</body>
|
| 90 |
-
</html>
|
| 91 |
-
"""
|
| 92 |
-
return html_content
|
| 93 |
-
|
| 94 |
-
@app.get("""/status")
|
| 95 |
-
async def get_status():
|
| 96 |
-
"""Get system status and information"""""
|
| 97 |
-
return {
|
| 98 |
-
"status": "🟢 ONLINE",
|
| 99 |
-
"api_name": "The-Chef's Epic API",
|
| 100 |
-
"version": "2.0.0",
|
| 101 |
-
"platform": platform.system(),
|
| 102 |
-
"python_version": platform.python_version(),
|
| 103 |
-
"uptime_message": "Running smooth like butter 😎",
|
| 104 |
-
"endpoints_available": 6,
|
| 105 |
-
"coolness_level": "Over 9000! 🔥"
|
| 106 |
-
}
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
async def random_fact():
|
| 110 |
-
"""Get a random interesting fact"""""
|
| 111 |
fact = random.choice(COOL_FACTS)
|
| 112 |
return {
|
| 113 |
"fact": fact,
|
| 114 |
-
"category": "mind = blown
|
| 115 |
"timestamp": datetime.now().isoformat()
|
| 116 |
}
|
| 117 |
|
| 118 |
@app.get("/motivate")
|
| 119 |
async def get_motivation():
|
| 120 |
-
"""Get a motivational quote"""""
|
| 121 |
quote = random.choice(MOTIVATIONAL_QUOTES)
|
| 122 |
return {
|
| 123 |
"quote": quote,
|
| 124 |
-
"message": "You got this!
|
| 125 |
-
"vibes": "Positive
|
| 126 |
"timestamp": datetime.now().isoformat()
|
| 127 |
}
|
| 128 |
|
| 129 |
@app.get("/time")
|
| 130 |
async def get_time():
|
| 131 |
-
"""Get current server time"""""
|
| 132 |
now = datetime.now()
|
| 133 |
return {
|
| 134 |
"current_time": now.isoformat(),
|
|
@@ -136,16 +85,15 @@ async def get_time():
|
|
| 136 |
"time": now.strftime("%H:%M:%S"),
|
| 137 |
"day_of_week": now.strftime("%A"),
|
| 138 |
"timezone": "UTC",
|
| 139 |
-
"message": "Time flies when you're having fun!
|
| 140 |
}
|
| 141 |
|
| 142 |
@app.get("/hello/{name}")
|
| 143 |
async def greet_user(name: str):
|
| 144 |
-
"""Personalized greeting"""""
|
| 145 |
greetings = ["Hey", "Hello", "Hi", "Yo", "What's up"]
|
| 146 |
greeting = random.choice(greetings)
|
| 147 |
return {
|
| 148 |
-
"message": f"{greeting}, {name}!
|
| 149 |
"status": "You're awesome!",
|
| 150 |
"coolness_boost": "+100 points"
|
| 151 |
}
|
|
@@ -153,7 +101,9 @@ async def greet_user(name: str):
|
|
| 153 |
}
|
| 154 |
}
|
| 155 |
}
|
| 156 |
-
|
|
|
|
|
|
|
| 157 |
]
|
| 158 |
]
|
| 159 |
)
|
|
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
| 2 |
import random
|
| 3 |
from datetime import datetime
|
| 4 |
import platform
|
| 5 |
|
| 6 |
app = FastAPI(
|
| 7 |
+
title="The-Chef's Epic API",
|
| 8 |
description="A seriously cool API with multiple endpoints",
|
| 9 |
version="2.0.0"
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
COOL_FACTS = [
|
| 13 |
"Honey never spoils. Archaeologists have found 3000-year-old honey in Egyptian tombs that's still edible.",
|
| 14 |
"A group of flamingos is called a 'flamboyance'.",
|
|
|
|
| 28 |
"Believe you can and you're halfway there. - Theodore Roosevelt"
|
| 29 |
]
|
| 30 |
|
| 31 |
+
@app.get("/")
|
| 32 |
async def root():
|
| 33 |
+
return {
|
| 34 |
+
"message": "Welcome to The-Chef's Epic API!",
|
| 35 |
+
"version": "2.0.0",
|
| 36 |
+
"endpoints": {
|
| 37 |
+
"/status": "Get system status and info",
|
| 38 |
+
"/random-fact": "Get a random cool fact",
|
| 39 |
+
"/motivate": "Get motivated with a quote",
|
| 40 |
+
"/time": "Get current server time",
|
| 41 |
+
"/hello/{name}": "Get a personalized greeting",
|
| 42 |
+
"/docs": "Interactive API documentation"
|
| 43 |
+
},
|
| 44 |
+
"coolness_level": "Over 9000!"
|
| 45 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
@app.get("/status")
|
| 48 |
+
async def get_status():
|
| 49 |
+
return {
|
| 50 |
+
"status": "ONLINE",
|
| 51 |
+
"api_name": "The-Chef's Epic API",
|
| 52 |
+
"version": "2.0.0",
|
| 53 |
+
"platform": platform.system(),
|
| 54 |
+
"python_version": platform.python_version(),
|
| 55 |
+
"uptime_message": "Running smooth like butter",
|
| 56 |
+
"endpoints_available": 6,
|
| 57 |
+
"coolness_level": "Over 9000!"
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
@app.get("/random-fact")
|
| 61 |
async def random_fact():
|
|
|
|
| 62 |
fact = random.choice(COOL_FACTS)
|
| 63 |
return {
|
| 64 |
"fact": fact,
|
| 65 |
+
"category": "mind = blown",
|
| 66 |
"timestamp": datetime.now().isoformat()
|
| 67 |
}
|
| 68 |
|
| 69 |
@app.get("/motivate")
|
| 70 |
async def get_motivation():
|
|
|
|
| 71 |
quote = random.choice(MOTIVATIONAL_QUOTES)
|
| 72 |
return {
|
| 73 |
"quote": quote,
|
| 74 |
+
"message": "You got this!",
|
| 75 |
+
"vibes": "Positive",
|
| 76 |
"timestamp": datetime.now().isoformat()
|
| 77 |
}
|
| 78 |
|
| 79 |
@app.get("/time")
|
| 80 |
async def get_time():
|
|
|
|
| 81 |
now = datetime.now()
|
| 82 |
return {
|
| 83 |
"current_time": now.isoformat(),
|
|
|
|
| 85 |
"time": now.strftime("%H:%M:%S"),
|
| 86 |
"day_of_week": now.strftime("%A"),
|
| 87 |
"timezone": "UTC",
|
| 88 |
+
"message": "Time flies when you're having fun!"
|
| 89 |
}
|
| 90 |
|
| 91 |
@app.get("/hello/{name}")
|
| 92 |
async def greet_user(name: str):
|
|
|
|
| 93 |
greetings = ["Hey", "Hello", "Hi", "Yo", "What's up"]
|
| 94 |
greeting = random.choice(greetings)
|
| 95 |
return {
|
| 96 |
+
"message": f"{greeting}, {name}!",
|
| 97 |
"status": "You're awesome!",
|
| 98 |
"coolness_boost": "+100 points"
|
| 99 |
}
|
|
|
|
| 101 |
}
|
| 102 |
}
|
| 103 |
}
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
]
|
| 108 |
]
|
| 109 |
)
|