Spaces:
Runtime error
Runtime error
tech-envision
commited on
Commit
·
6ebba8f
1
Parent(s):
2a103fa
Add CORS and modernize frontend
Browse files- api_app/__init__.py +9 -0
- frontend/index.html +6 -0
- frontend/src/index.css +6 -3
- frontend/src/styles/chat.css +17 -4
api_app/__init__.py
CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
3 |
from fastapi import FastAPI, UploadFile, File, Form
|
4 |
from fastapi.responses import StreamingResponse
|
5 |
from fastapi import HTTPException
|
|
|
6 |
from pydantic import BaseModel
|
7 |
import asyncio
|
8 |
import os
|
@@ -26,6 +27,14 @@ class ChatRequest(BaseModel):
|
|
26 |
def create_app() -> FastAPI:
|
27 |
app = FastAPI(title="LLM Backend API")
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
@app.post("/chat/stream")
|
30 |
async def chat_stream(req: ChatRequest):
|
31 |
async def stream() -> asyncio.AsyncIterator[str]:
|
|
|
3 |
from fastapi import FastAPI, UploadFile, File, Form
|
4 |
from fastapi.responses import StreamingResponse
|
5 |
from fastapi import HTTPException
|
6 |
+
from fastapi.middleware.cors import CORSMiddleware
|
7 |
from pydantic import BaseModel
|
8 |
import asyncio
|
9 |
import os
|
|
|
27 |
def create_app() -> FastAPI:
|
28 |
app = FastAPI(title="LLM Backend API")
|
29 |
|
30 |
+
app.add_middleware(
|
31 |
+
CORSMiddleware,
|
32 |
+
allow_origins=["*"],
|
33 |
+
allow_credentials=True,
|
34 |
+
allow_methods=["*"],
|
35 |
+
allow_headers=["*"],
|
36 |
+
)
|
37 |
+
|
38 |
@app.post("/chat/stream")
|
39 |
async def chat_stream(req: ChatRequest):
|
40 |
async def stream() -> asyncio.AsyncIterator[str]:
|
frontend/index.html
CHANGED
@@ -3,6 +3,12 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
<title>LLM Chat</title>
|
8 |
</head>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
6 |
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
7 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
8 |
+
<link
|
9 |
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
10 |
+
rel="stylesheet"
|
11 |
+
/>
|
12 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
13 |
<title>LLM Chat</title>
|
14 |
</head>
|
frontend/src/index.css
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
:root {
|
2 |
-
--glass-bg: rgba(255, 255, 255, 0.
|
3 |
-
--glass-border: rgba(255, 255, 255, 0.
|
4 |
--blur: 16px;
|
5 |
--radius: 20px;
|
|
|
6 |
}
|
7 |
|
8 |
* {
|
@@ -12,7 +13,7 @@
|
|
12 |
body {
|
13 |
margin: 0;
|
14 |
padding: 0;
|
15 |
-
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
16 |
background: linear-gradient(120deg, #89f7fe 0%, #66a6ff 100%);
|
17 |
display: flex;
|
18 |
justify-content: center;
|
@@ -31,6 +32,8 @@ body::after {
|
|
31 |
background: radial-gradient(circle at center, rgba(255, 255, 255, 0.5), transparent);
|
32 |
filter: blur(100px);
|
33 |
z-index: 0;
|
|
|
|
|
34 |
}
|
35 |
|
36 |
body::before {
|
|
|
1 |
:root {
|
2 |
+
--glass-bg: rgba(255, 255, 255, 0.15);
|
3 |
+
--glass-border: rgba(255, 255, 255, 0.35);
|
4 |
--blur: 16px;
|
5 |
--radius: 20px;
|
6 |
+
--glare: radial-gradient(circle at top left, rgba(255, 255, 255, 0.6), transparent);
|
7 |
}
|
8 |
|
9 |
* {
|
|
|
13 |
body {
|
14 |
margin: 0;
|
15 |
padding: 0;
|
16 |
+
font-family: 'Inter', system-ui, Avenir, Helvetica, Arial, sans-serif;
|
17 |
background: linear-gradient(120deg, #89f7fe 0%, #66a6ff 100%);
|
18 |
display: flex;
|
19 |
justify-content: center;
|
|
|
32 |
background: radial-gradient(circle at center, rgba(255, 255, 255, 0.5), transparent);
|
33 |
filter: blur(100px);
|
34 |
z-index: 0;
|
35 |
+
mix-blend-mode: overlay;
|
36 |
+
opacity: 0.6;
|
37 |
}
|
38 |
|
39 |
body::before {
|
frontend/src/styles/chat.css
CHANGED
@@ -11,6 +11,17 @@
|
|
11 |
border-radius: var(--radius);
|
12 |
padding: 1rem;
|
13 |
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
|
16 |
.message-list {
|
@@ -20,6 +31,7 @@
|
|
20 |
flex-direction: column;
|
21 |
gap: 0.5rem;
|
22 |
padding-right: 4px;
|
|
|
23 |
}
|
24 |
|
25 |
.session-list {
|
@@ -38,6 +50,7 @@
|
|
38 |
backdrop-filter: blur(var(--blur));
|
39 |
-webkit-backdrop-filter: blur(var(--blur));
|
40 |
font-size: 0.75rem;
|
|
|
41 |
}
|
42 |
|
43 |
.session-item.active {
|
@@ -54,7 +67,7 @@
|
|
54 |
border-radius: var(--radius);
|
55 |
backdrop-filter: blur(var(--blur));
|
56 |
-webkit-backdrop-filter: blur(var(--blur));
|
57 |
-
animation: jelly 0.6s
|
58 |
}
|
59 |
|
60 |
.message.user {
|
@@ -87,7 +100,7 @@
|
|
87 |
color: #000;
|
88 |
font-weight: bold;
|
89 |
cursor: pointer;
|
90 |
-
transition: transform 0.2s;
|
91 |
}
|
92 |
|
93 |
.username-form {
|
@@ -119,7 +132,7 @@
|
|
119 |
background: rgba(255, 255, 255, 0.7);
|
120 |
font-weight: bold;
|
121 |
cursor: pointer;
|
122 |
-
transition: transform 0.2s;
|
123 |
}
|
124 |
|
125 |
.username-form button:hover {
|
@@ -146,7 +159,7 @@
|
|
146 |
transform: scale(1.05);
|
147 |
}
|
148 |
60% {
|
149 |
-
transform: scale(0.
|
150 |
}
|
151 |
100% {
|
152 |
transform: scale(1);
|
|
|
11 |
border-radius: var(--radius);
|
12 |
padding: 1rem;
|
13 |
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
|
14 |
+
position: relative;
|
15 |
+
overflow: hidden;
|
16 |
+
}
|
17 |
+
|
18 |
+
.chat-container::before {
|
19 |
+
content: '';
|
20 |
+
position: absolute;
|
21 |
+
inset: 0;
|
22 |
+
background: var(--glare);
|
23 |
+
mix-blend-mode: overlay;
|
24 |
+
pointer-events: none;
|
25 |
}
|
26 |
|
27 |
.message-list {
|
|
|
31 |
flex-direction: column;
|
32 |
gap: 0.5rem;
|
33 |
padding-right: 4px;
|
34 |
+
scroll-behavior: smooth;
|
35 |
}
|
36 |
|
37 |
.session-list {
|
|
|
50 |
backdrop-filter: blur(var(--blur));
|
51 |
-webkit-backdrop-filter: blur(var(--blur));
|
52 |
font-size: 0.75rem;
|
53 |
+
transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
|
54 |
}
|
55 |
|
56 |
.session-item.active {
|
|
|
67 |
border-radius: var(--radius);
|
68 |
backdrop-filter: blur(var(--blur));
|
69 |
-webkit-backdrop-filter: blur(var(--blur));
|
70 |
+
animation: jelly 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
71 |
}
|
72 |
|
73 |
.message.user {
|
|
|
100 |
color: #000;
|
101 |
font-weight: bold;
|
102 |
cursor: pointer;
|
103 |
+
transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
|
104 |
}
|
105 |
|
106 |
.username-form {
|
|
|
132 |
background: rgba(255, 255, 255, 0.7);
|
133 |
font-weight: bold;
|
134 |
cursor: pointer;
|
135 |
+
transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
|
136 |
}
|
137 |
|
138 |
.username-form button:hover {
|
|
|
159 |
transform: scale(1.05);
|
160 |
}
|
161 |
60% {
|
162 |
+
transform: scale(0.97);
|
163 |
}
|
164 |
100% {
|
165 |
transform: scale(1);
|