Skip to content

Commit 7adc537

Browse files
author
yashksaini-coder
committed
feat: implement root endpoint and add base HTML template for improved UI
1 parent 62b9a77 commit 7adc537

File tree

2 files changed

+118
-5
lines changed

2 files changed

+118
-5
lines changed

app.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# API imports
2-
from fastapi import FastAPI
2+
from fastapi import FastAPI, Request
33
import groq
44
import os
55
from dotenv import load_dotenv
6+
import datetime
7+
import requests
8+
69
from fastapi.middleware.cors import CORSMiddleware
10+
from fastapi.responses import HTMLResponse
11+
from fastapi.templating import Jinja2Templates
12+
from pyfiglet import Figlet, FigletFont
13+
14+
# Custom imports
715
from topStocks import get_top_stocks
816
from agents import multi_ai
917
from agno.agent import RunResponse
10-
import datetime
11-
import requests
18+
19+
20+
templates = Jinja2Templates(directory="templates")
1221

1322
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
1423
groq_client = groq.Client(api_key=GROQ_API_KEY)
@@ -25,6 +34,12 @@
2534
allow_headers=["*"],
2635
)
2736

37+
@app.get("/")
38+
async def read_root(request: Request):
39+
text = "Investo-glow Backend API Server"
40+
return templates.TemplateResponse("base.html",{"request":request, "text": text})
41+
42+
2843
@app.get("/top-stocks")
2944
async def read_top_stocks():
3045
top_stocks = ['AAPL', 'MSFT', 'AMZN', 'GOOGL']
@@ -34,8 +49,8 @@ async def read_top_stocks():
3449

3550
@app.get("/")
3651
async def read_root():
37-
return {"message": "Welcome to the Investo-glow Backend API!"}
38-
52+
return {"Welcome to the Investo-glow Backend API!"}
53+
return templates.TemplateResponse("home.html",{"request": request, "home_art": home_art})
3954

4055
@app.get("health/") # Changed to GET since it's retrieving status
4156
async def health_check():

templates/base.html

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Investo</title>
7+
<link rel="preconnect" href="https://fonts.googleapis.com">
8+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9+
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&family=Source+Code+Pro:ital,wght@0,200..900;1,200..900&display=swap" rel="stylesheet">
10+
<style>
11+
html {
12+
background-color: black;
13+
font-family: 'JetBrains Mono', monospace;
14+
box-sizing: border-box;
15+
font-size: 8px;
16+
padding: 15px;
17+
display: flex;
18+
flex-direction: column;
19+
min-height: 100vh;
20+
}
21+
22+
*, *:before, *:after {
23+
box-sizing: inherit;
24+
}
25+
26+
pre{
27+
color: rgb(41, 199, 162);
28+
}
29+
30+
main, h1, h2, h3, h4, h5, h6, p, ol, ul {
31+
font-size: 18px;
32+
font-weight: normal;
33+
color: white;
34+
margin-bottom: 80px;
35+
}
36+
37+
footer{
38+
margin-top: 30px;
39+
display: flex;
40+
align-items: center;
41+
justify-content: center;
42+
font-size: 6px;
43+
44+
}
45+
46+
.blinking_bar {
47+
font-size: 2px;
48+
color: white;
49+
background-color: black;
50+
padding: 3px;
51+
border: 2px solid white;
52+
animation: blink 1s infinite;
53+
width: 2px;
54+
height: 15px;
55+
}
56+
57+
@keyframes blink {
58+
0% {
59+
background-color: black;
60+
color: white;
61+
}
62+
50% {
63+
background-color: white;
64+
color: black;
65+
}
66+
100% {
67+
background-color: black;
68+
color: white;
69+
}
70+
}
71+
72+
</style>
73+
{% block title %}
74+
{% endblock %}
75+
</head>
76+
<pre>
77+
{% block header %}
78+
██╗███╗ ██╗██╗ ██╗███████╗███████╗████████╗ ██████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗
79+
██║████╗ ██║██║ ██║██╔════╝██╔════╝╚══██╔══╝██╔═══██╗ ██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗
80+
██║██╔██╗ ██║██║ ██║█████╗ ███████╗ ██║ ██║ ██║ ███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝
81+
██║██║╚██╗██║╚██╗ ██╔╝██╔══╝ ╚════██║ ██║ ██║ ██║ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗
82+
██║██║ ╚████║ ╚████╔╝ ███████╗███████║ ██║ ╚██████╔╝ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║
83+
╚═╝╚═╝ ╚═══╝ ╚═══╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
84+
{% endblock %}
85+
</pre>
86+
<body>
87+
<main>
88+
{% block content %}
89+
<div style="display: flex; align-items: center;">
90+
<div class="blinking_bar" style="margin-right: 8px;"></div> {{text}}
91+
</div>
92+
{% endblock %}
93+
</main>
94+
<!-- <footer>
95+
<p>Investo &copy; 2021</p>
96+
</footer> -->
97+
</body>
98+
</html>

0 commit comments

Comments
 (0)