Spaces:
Running
Running
Robin
commited on
Commit
·
20a632a
1
Parent(s):
96d2860
static files mount
Browse files- app.py +14 -1
- static/index.html +1 -1
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, Request
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
3 |
from pydantic import BaseModel
|
4 |
import os
|
5 |
import json
|
@@ -14,6 +15,18 @@ from utils import model, trump_character, client
|
|
14 |
|
15 |
app = FastAPI()
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
class Message(BaseModel):
|
18 |
message: str
|
19 |
|
@@ -60,7 +73,7 @@ def generate_text(message: Message):
|
|
60 |
"chat_history": chat_history
|
61 |
}
|
62 |
|
63 |
-
@app.post("/generate-text")
|
64 |
def inference(message: Message, request: Request):
|
65 |
if request.headers.get("origin") != "https://Mistral-AI-Game-Jam/team13.static.hf.space":
|
66 |
return 204
|
|
|
1 |
from fastapi import FastAPI, HTTPException, Request
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
from pydantic import BaseModel
|
5 |
import os
|
6 |
import json
|
|
|
15 |
|
16 |
app = FastAPI()
|
17 |
|
18 |
+
# Add CORS middleware
|
19 |
+
app.add_middleware(
|
20 |
+
CORSMiddleware,
|
21 |
+
allow_origins=["*"],
|
22 |
+
allow_credentials=True,
|
23 |
+
allow_methods=["*"],
|
24 |
+
allow_headers=["*"],
|
25 |
+
)
|
26 |
+
|
27 |
+
# Mount static files
|
28 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
29 |
+
|
30 |
class Message(BaseModel):
|
31 |
message: str
|
32 |
|
|
|
73 |
"chat_history": chat_history
|
74 |
}
|
75 |
|
76 |
+
@app.post("/api/generate-text")
|
77 |
def inference(message: Message, request: Request):
|
78 |
if request.headers.get("origin") != "https://Mistral-AI-Game-Jam/team13.static.hf.space":
|
79 |
return 204
|
static/index.html
CHANGED
@@ -69,7 +69,7 @@
|
|
69 |
messageInput.value = '';
|
70 |
|
71 |
// Send to API
|
72 |
-
fetch('/generate-text', {
|
73 |
method: 'POST',
|
74 |
headers: {
|
75 |
'Content-Type': 'application/json'
|
|
|
69 |
messageInput.value = '';
|
70 |
|
71 |
// Send to API
|
72 |
+
fetch('/api/generate-text', {
|
73 |
method: 'POST',
|
74 |
headers: {
|
75 |
'Content-Type': 'application/json'
|