Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -354,7 +354,46 @@ async def root():
|
|
| 354 |
if html_content is None:
|
| 355 |
return HTMLResponse(content="<h1>File not found</h1>", status_code=404)
|
| 356 |
return HTMLResponse(content=html_content)
|
| 357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
@app.get("/playground", response_class=HTMLResponse)
|
| 359 |
async def playground():
|
| 360 |
html_content = read_html_file("playground.html")
|
|
|
|
| 354 |
if html_content is None:
|
| 355 |
return HTMLResponse(content="<h1>File not found</h1>", status_code=404)
|
| 356 |
return HTMLResponse(content=html_content)
|
| 357 |
+
|
| 358 |
+
@app.get("/dynamo", response_class=HTMLResponse)
|
| 359 |
+
async def dynamic_ai_page(request: Request):
|
| 360 |
+
user_agent = request.headers.get('user-agent', 'Unknown User')
|
| 361 |
+
client_ip = request.client.host
|
| 362 |
+
location = f"IP: {client_ip}"
|
| 363 |
+
|
| 364 |
+
prompt = f"""
|
| 365 |
+
Generate a dynamic HTML page for a user with the following details: with name "LOKI.AI"
|
| 366 |
+
- User-Agent: {user_agent}
|
| 367 |
+
- Location: {location}
|
| 368 |
+
- Style: Cyberpunk, minimalist, or retro
|
| 369 |
+
|
| 370 |
+
Make sure the HTML is clean and includes a heading, also have cool animations a motivational message, and a cool background.
|
| 371 |
+
Wrap the generated HTML in triple backticks (```).
|
| 372 |
+
"""
|
| 373 |
+
|
| 374 |
+
payload = {
|
| 375 |
+
"model": "open-mistral-nemo",
|
| 376 |
+
"messages": [{"role": "user", "content": prompt}]
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
headers = {
|
| 380 |
+
"Authorization": "Bearer playground"
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
response = requests.post("https://parthsadaria-lokiai.hf.space/chat/completions", json=payload, headers=headers)
|
| 384 |
+
data = response.json()
|
| 385 |
+
|
| 386 |
+
# Extract HTML from ``` blocks
|
| 387 |
+
html_content = re.search(r"```(.*?)```", data['choices'][0]['message']['content'], re.DOTALL)
|
| 388 |
+
if html_content:
|
| 389 |
+
html_content = html_content.group(1).strip()
|
| 390 |
+
|
| 391 |
+
# Remove the first word
|
| 392 |
+
if html_content:
|
| 393 |
+
html_content = ' '.join(html_content.split(' ')[1:])
|
| 394 |
+
|
| 395 |
+
return HTMLResponse(content=html_content)
|
| 396 |
+
|
| 397 |
@app.get("/playground", response_class=HTMLResponse)
|
| 398 |
async def playground():
|
| 399 |
html_content = read_html_file("playground.html")
|