The-Chef commited on
Commit
1e3f83d
Β·
verified Β·
1 Parent(s): cdcaab6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -4
app.py CHANGED
@@ -1,7 +1,159 @@
1
  from fastapi import FastAPI
 
 
 
 
2
 
3
- app = FastAPI()
 
 
 
 
4
 
5
- @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="πŸ”₯ The-Chef's Epic API πŸ”₯",
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'.",
17
+ "Octopuses have three hearts and blue blood.",
18
+ "Bananas are berries, but strawberries aren't.",
19
+ "There are more stars in the universe than grains of sand on all Earth's beaches.",
20
+ "Water can boil and freeze at the same time (triple point).",
21
+ "A day on Venus is longer than its year.",
22
+ "Your body produces enough heat in 30 minutes to bring water to a boil."
23
+ ]
24
+
25
+ MOTIVATIONAL_QUOTES = [
26
+ "The only way to do great work is to love what you do. - Steve Jobs",
27
+ "Innovation distinguishes between a leader and a follower. - Steve Jobs",
28
+ "The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
29
+ "Success is not final, failure is not fatal: it is the courage to continue that counts. - Winston Churchill",
30
+ "Believe you can and you're halfway there. - Theodore Roosevelt"
31
+ ]
32
+
33
+ @app.get("/", response_class=HTMLResponse)
34
+ async def root():
35
+ """Welcome page with API documentation"""""
36
+ html_content = """
37
+ <html>
38
+ <head>
39
+ <title>The-Chef's Epic API</title>
40
+ <style>
41
+ body {
42
+ font-family: 'Courier New', monospace;
43
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
44
+ color: white;
45
+ padding: 50px;
46
+ text-align: center;
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
+ @app.get("/random-fact")
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(),
135
+ "date": now.strftime("%Y-%m-%d"),
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
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ ]
158
+ ]
159
+ )