Update app.py
Browse files1234563789101112567131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159from fastapi import FastAPIfrom fastapi.responses import HTMLResponseimport randomfrom datetime import datetimeimport platform
app = FastAPI()app = FastAPI( title="π₯ The-Chef's Epic API π₯", description="A seriously cool API with multiple endpoints", version="2.0.0")
@app.get("/")def greet_json(): return {"Hello": "World!"}# Cool facts databaseCOOL_FACTS = [ "Honey never spoils. Archaeologists have found 3000-year-old honey in Egyptian tombs that's still edible.", "A group of flamingos is called a 'flamboyance'.", "Octopuses have three hearts and blue blood.", "Bananas are berries, but strawberries aren't.", "There are more stars in the universe than grains of sand on all Earth's beaches.", "Water can boil and freeze at the same time (triple point).", "A day on Venus is longer than its year.", "Your body produces enough heat in 30 minutes to bring water to a boil."]
MOTIVATIONAL_QUOTES = [ "The only way to do great work is to love what you do. - Steve Jobs", "Innovation distinguishes between a leader and a follower. - Steve Jobs", "The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt", "Success is not final, failure is not fatal: it is the courage to continue that counts. - Winston Churchill", "Believe you can and you're halfway there. - Theodore Roosevelt"]
@app.get("/", response_class=HTMLResponse)async def root(): """Welcome page with API documentation""""" html_content = """ <html> <head> <title>The-Chef's Epic API</title> <style> body { font-family: 'Courier New', monospace; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 50px; text-align: center; } .container { background: rgba(0,0,0,0.3); border-radius: 20px; padding: 40px; max-width: 800px; margin: 0 auto; backdrop-filter: blur(10px); } h1 { font-size: 3em; margin-bottom: 20px; } .endpoint { background: rgba(255,255,255,0.1); padding: 15px; margin: 10px 0; border-radius: 10px; text-align: left; } a { color: #ffd700; text-decoration: none; font-weight: bold; } a:hover { text-decoration: underline; } </style> </head> <body> <div class="""container"> <h1>π The-Chef's Epic API π</h1> <p>Welcome to the coolest API on Hugging Face Spaces!</p> <h2>π‘ Available Endpoints:</h2> <div class="endpoint"> <strong>GET <a href="/status">/status</a></strong> - System status & info </div> <div class="endpoint"> <strong>GET <a href="/random-fact">/random-fact</a></strong> - Get a random cool fact </div> <div class="endpoint"> <strong>GET <a href="/motivate">/motivate</a></strong> - Get motivated! </div> <div class="endpoint"> <strong>GET <a href="/time">/time</a></strong> - Current server time </div> <div class="endpoint"> <strong>GET <a href="/docs">/docs</a></strong> - Interactive API documentation </div> </div> </body> </html> """ return html_content @app.get("""/status") async def get_status(): """Get system status and information""""" return { "status": "π’ ONLINE", "api_name": "The-Chef's Epic API", "version": "2.0.0", "platform": platform.system(), "python_version": platform.python_version(), "uptime_message": "Running smooth like butter π", "endpoints_available": 6, "coolness_level": "Over 9000! π₯" }
@app.get("/random-fact")async def random_fact(): """Get a random interesting fact""""" fact = random.choice(COOL_FACTS) return { "fact": fact, "category": "mind = blown π€―", "timestamp": datetime.now().isoformat() }
@app.get("/motivate")async def get_motivation(): """Get a motivational quote""""" quote = random.choice(MOTIVATIONAL_QUOTES) return { "quote": quote, "message": "You got this! πͺ", "vibes": "Positive β¨", "timestamp": datetime.now().isoformat() }
@app.get("/time")async def get_time(): """Get current server time""""" now = datetime.now() return { "current_time": now.isoformat(), "date": now.strftime("%Y-%m-%d"), "time": now.strftime("%H:%M:%S"), "day_of_week": now.strftime("%A"), "timezone": "UTC", "message": "Time flies when you're having fun! β°" }
@app.get("/hello/{name}")async def greet_user(name: str): """Personalized greeting""""" greetings = ["Hey", "Hello", "Hi", "Yo", "What's up"] greeting = random.choice(greetings) return { "message": f"{greeting}, {name}! π", "status": "You're awesome!", "coolness_boost": "+100 points" } } } } } }]])app.py+156-4