Spaces:
Sleeping
Sleeping
Initial commit
Browse files- README.md +14 -0
- app.py +21 -9
- templates/index.html +104 -0
README.md
CHANGED
|
@@ -113,4 +113,18 @@ ai-server/
|
|
| 113 |
### π ν
μ€νΈ
|
| 114 |
μ
λ°μ΄νΈ μμ
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
---
|
|
|
|
| 113 |
### π ν
μ€νΈ
|
| 114 |
μ
λ°μ΄νΈ μμ
|
| 115 |
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
<!-- app-tab:start -->
|
| 119 |
+
# π PersonaChatEngine AI Server
|
| 120 |
+
|
| 121 |
+
κ²μ λ΄ NPC λν μμ§ API μλ²μ
λλ€.
|
| 122 |
+
μ΅μ μ
λ ₯λ§μΌλ‘λ λμνλ©°, RAG κΈ°λ° λ¬Έμμ NPC λ©νλ°μ΄ν°λ₯Ό νμ©ν΄ λνλ₯Ό 보κ°ν©λλ€.
|
| 123 |
+
|
| 124 |
+
### βοΈ μ£Όμ κΈ°λ₯
|
| 125 |
+
- κ²μ μλ² μμ² μμ λ° μ μ²λ¦¬
|
| 126 |
+
- 쑰건 νμ ν λ©μΈ/ν΄λ°± λͺ¨λΈ μΆλ‘
|
| 127 |
+
- RAG κΈ°λ° μΈκ³κ΄Β·μν©Β·NPC μ±κ²© λ°μ
|
| 128 |
+
- μλ΅ νμ²λ¦¬ λ° JSON νμ€ μλ΅ λ°ν
|
| 129 |
+
<!-- app-tab:end -->
|
| 130 |
---
|
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
import asyncio
|
|
|
|
|
|
|
| 2 |
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from fastapi.
|
| 5 |
from contextlib import asynccontextmanager
|
|
|
|
| 6 |
from manager.dialogue_manager import handle_dialogue
|
| 7 |
from rag.rag_manager import chroma_initialized, load_game_docs_from_disk, add_docs, set_embedder
|
| 8 |
from models.model_loader import load_fallback_model, load_embedder
|
|
@@ -13,7 +16,8 @@ from config import (
|
|
| 13 |
HF_TOKEN, BASE_DIR
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
async def load_models(app: FastAPI):
|
| 19 |
global model_ready
|
|
@@ -39,7 +43,7 @@ async def load_models(app: FastAPI):
|
|
| 39 |
|
| 40 |
@asynccontextmanager
|
| 41 |
async def lifespan(app: FastAPI):
|
| 42 |
-
asyncio.create_task(load_models(app))
|
| 43 |
yield
|
| 44 |
print("π μλ² μ’
λ£ μ€...")
|
| 45 |
|
|
@@ -54,12 +58,19 @@ app.add_middleware(
|
|
| 54 |
)
|
| 55 |
|
| 56 |
@app.get("/", include_in_schema=False)
|
| 57 |
-
async def root():
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
@app.get("/status")
|
| 65 |
async def status():
|
|
@@ -95,6 +106,7 @@ async def ask(request: Request, req: AskReq):
|
|
| 95 |
)
|
| 96 |
|
| 97 |
|
|
|
|
| 98 |
'''
|
| 99 |
μ΅μ’
gameβserver β aiβserver μμ² μμ
|
| 100 |
{
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import markdown
|
| 4 |
from fastapi import FastAPI, Request, HTTPException
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
+
from fastapi.templating import Jinja2Templates
|
| 7 |
from contextlib import asynccontextmanager
|
| 8 |
+
|
| 9 |
from manager.dialogue_manager import handle_dialogue
|
| 10 |
from rag.rag_manager import chroma_initialized, load_game_docs_from_disk, add_docs, set_embedder
|
| 11 |
from models.model_loader import load_fallback_model, load_embedder
|
|
|
|
| 16 |
HF_TOKEN, BASE_DIR
|
| 17 |
)
|
| 18 |
|
| 19 |
+
templates = Jinja2Templates(directory="templates")
|
| 20 |
+
model_ready = False
|
| 21 |
|
| 22 |
async def load_models(app: FastAPI):
|
| 23 |
global model_ready
|
|
|
|
| 43 |
|
| 44 |
@asynccontextmanager
|
| 45 |
async def lifespan(app: FastAPI):
|
| 46 |
+
asyncio.create_task(load_models(app))
|
| 47 |
yield
|
| 48 |
print("π μλ² μ’
λ£ μ€...")
|
| 49 |
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
@app.get("/", include_in_schema=False)
|
| 61 |
+
async def root(request: Request):
|
| 62 |
+
md_path = Path(__file__).parent / "README.md"
|
| 63 |
+
md_content = md_path.read_text(encoding="utf-8")
|
| 64 |
+
|
| 65 |
+
start_tag = "<!-- app-tab:start -->"
|
| 66 |
+
end_tag = "<!-- app-tab:end -->"
|
| 67 |
+
if start_tag in md_content and end_tag in md_content:
|
| 68 |
+
short_md = md_content.split(start_tag)[1].split(end_tag)[0].strip()
|
| 69 |
+
else:
|
| 70 |
+
short_md = md_content # fallback: μ 체 λ΄μ©
|
| 71 |
+
|
| 72 |
+
html_from_md = markdown.markdown(short_md)
|
| 73 |
+
return templates.TemplateResponse("index.html", {"request": request, "readme_content": html_from_md})
|
| 74 |
|
| 75 |
@app.get("/status")
|
| 76 |
async def status():
|
|
|
|
| 106 |
)
|
| 107 |
|
| 108 |
|
| 109 |
+
|
| 110 |
'''
|
| 111 |
μ΅μ’
gameβserver β aiβserver μμ² μμ
|
| 112 |
{
|
templates/index.html
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<title>PersonaChatEngine AI Server</title>
|
| 6 |
+
<style>
|
| 7 |
+
/* λ€ν¬λͺ¨λ κΈ°λ³Έ μ€νμΌ */
|
| 8 |
+
body {
|
| 9 |
+
font-family: 'Segoe UI', Arial, sans-serif;
|
| 10 |
+
margin: 0;
|
| 11 |
+
background-color: #0d1117;
|
| 12 |
+
color: #e6edf3;
|
| 13 |
+
}
|
| 14 |
+
header {
|
| 15 |
+
background-color: #161b22;
|
| 16 |
+
padding: 20px 40px;
|
| 17 |
+
text-align: center;
|
| 18 |
+
border-bottom: 1px solid #30363d;
|
| 19 |
+
}
|
| 20 |
+
header h1 {
|
| 21 |
+
margin: 0;
|
| 22 |
+
font-size: 1.8em;
|
| 23 |
+
background: linear-gradient(90deg, #58a6ff, #a371f7);
|
| 24 |
+
-webkit-background-clip: text;
|
| 25 |
+
-webkit-text-fill-color: transparent;
|
| 26 |
+
}
|
| 27 |
+
header p {
|
| 28 |
+
margin: 5px 0 0;
|
| 29 |
+
color: #8b949e;
|
| 30 |
+
}
|
| 31 |
+
main {
|
| 32 |
+
max-width: 900px;
|
| 33 |
+
margin: 40px auto;
|
| 34 |
+
background-color: #161b22;
|
| 35 |
+
padding: 30px;
|
| 36 |
+
border-radius: 12px;
|
| 37 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
|
| 38 |
+
border: 1px solid #30363d;
|
| 39 |
+
}
|
| 40 |
+
h1, h2, h3 {
|
| 41 |
+
color: #58a6ff;
|
| 42 |
+
}
|
| 43 |
+
p, ul {
|
| 44 |
+
line-height: 1.6;
|
| 45 |
+
}
|
| 46 |
+
ul {
|
| 47 |
+
padding-left: 20px;
|
| 48 |
+
}
|
| 49 |
+
/* λ²νΌ μ€νμΌ */
|
| 50 |
+
a.button {
|
| 51 |
+
display: inline-block;
|
| 52 |
+
margin: 15px 10px 0 0;
|
| 53 |
+
padding: 12px 20px;
|
| 54 |
+
background: linear-gradient(135deg, #58a6ff, #a371f7);
|
| 55 |
+
color: white;
|
| 56 |
+
text-decoration: none;
|
| 57 |
+
border-radius: 8px;
|
| 58 |
+
font-weight: bold;
|
| 59 |
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
| 60 |
+
box-shadow: 0 4px 14px rgba(88, 166, 255, 0.4);
|
| 61 |
+
}
|
| 62 |
+
a.button:hover {
|
| 63 |
+
transform: translateY(-2px);
|
| 64 |
+
box-shadow: 0 6px 20px rgba(88, 166, 255, 0.6);
|
| 65 |
+
}
|
| 66 |
+
.button-container {
|
| 67 |
+
display: flex;
|
| 68 |
+
justify-content: center;
|
| 69 |
+
gap: 25px;
|
| 70 |
+
margin-top: 20px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
footer {
|
| 74 |
+
text-align: center;
|
| 75 |
+
font-size: 0.85em;
|
| 76 |
+
color: #8b949e;
|
| 77 |
+
margin: 40px 0 20px;
|
| 78 |
+
}
|
| 79 |
+
/* λ§ν¬ μμ */
|
| 80 |
+
a {
|
| 81 |
+
color: #58a6ff;
|
| 82 |
+
}
|
| 83 |
+
a:hover {
|
| 84 |
+
text-decoration: underline;
|
| 85 |
+
}
|
| 86 |
+
</style>
|
| 87 |
+
</head>
|
| 88 |
+
<body>
|
| 89 |
+
<header>
|
| 90 |
+
<h1>PersonaChatEngine AI Server</h1>
|
| 91 |
+
<p>κ²μ λ΄ NPC λν μμ§ API</p>
|
| 92 |
+
</header>
|
| 93 |
+
<main>
|
| 94 |
+
{{ readme_content|safe }}
|
| 95 |
+
<div class="button-container">
|
| 96 |
+
<a class="button" href="/docs" target="_blank">π API ν
μ€νΈνκΈ°</a>
|
| 97 |
+
<a class="button" href="https://huggingface.co/spaces/m97j/PersonaChatEngine_ai_server/blob/main/README.md" target="_blank">π μμΈ λ¬Έμ 보기</a>
|
| 98 |
+
</div>
|
| 99 |
+
</main>
|
| 100 |
+
<footer>
|
| 101 |
+
© 2025 PersonaChatEngine Project
|
| 102 |
+
</footer>
|
| 103 |
+
</body>
|
| 104 |
+
</html>
|