Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ from fastapi import FastAPI, Request
|
|
| 18 |
import uvicorn
|
| 19 |
|
| 20 |
# --- Settings ---
|
| 21 |
-
HF_TOKEN = os.getenv("HF_TOKEN") #
|
| 22 |
MODEL_NAME = "openai/gpt-oss-20b"
|
| 23 |
SYSTEM_MESSAGE = "You are Persaillia AI. You love coding and talking about airplanes."
|
| 24 |
DEFAULT_MAX_TOKENS = 512
|
|
@@ -49,8 +49,11 @@ async def chat_endpoint(req: Request):
|
|
| 49 |
def respond(message, history):
|
| 50 |
history = history or []
|
| 51 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 54 |
completion = client.chat_completion(
|
| 55 |
messages,
|
| 56 |
max_tokens=DEFAULT_MAX_TOKENS,
|
|
@@ -61,15 +64,14 @@ def respond(message, history):
|
|
| 61 |
history.append((message, reply))
|
| 62 |
return history, history
|
| 63 |
|
| 64 |
-
# --- Gradio
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
chatbot.blocks.insert(1, gr.Markdown("π **Space URL:** [https://huggingface.co/spaces/phaseDoutAI/persillia-AI](https://huggingface.co/spaces/phaseDoutAI/persillia-AI)"))
|
| 70 |
|
| 71 |
# --- Mount Gradio to FastAPI ---
|
| 72 |
-
app = gr.mount_gradio_app(api,
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 18 |
import uvicorn
|
| 19 |
|
| 20 |
# --- Settings ---
|
| 21 |
+
HF_TOKEN = os.getenv("HF_TOKEN") # set in Space secrets
|
| 22 |
MODEL_NAME = "openai/gpt-oss-20b"
|
| 23 |
SYSTEM_MESSAGE = "You are Persaillia AI. You love coding and talking about airplanes."
|
| 24 |
DEFAULT_MAX_TOKENS = 512
|
|
|
|
| 49 |
def respond(message, history):
|
| 50 |
history = history or []
|
| 51 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 52 |
+
for user, bot in history:
|
| 53 |
+
messages.append({"role": "user", "content": user})
|
| 54 |
+
messages.append({"role": "assistant", "content": bot})
|
| 55 |
messages.append({"role": "user", "content": message})
|
| 56 |
+
|
| 57 |
completion = client.chat_completion(
|
| 58 |
messages,
|
| 59 |
max_tokens=DEFAULT_MAX_TOKENS,
|
|
|
|
| 64 |
history.append((message, reply))
|
| 65 |
return history, history
|
| 66 |
|
| 67 |
+
# --- Gradio UI wrapped in Blocks ---
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("### π Persaillia AI β running on Hugging Face Spaces")
|
| 70 |
+
gr.Markdown("π **Space URL:** [https://huggingface.co/spaces/phaseDoutAI/persillia-AI](https://huggingface.co/spaces/phaseDoutAI/persillia-AI)")
|
| 71 |
+
gr.ChatInterface(fn=respond, type="messages")
|
|
|
|
| 72 |
|
| 73 |
# --- Mount Gradio to FastAPI ---
|
| 74 |
+
app = gr.mount_gradio_app(api, demo, path="/")
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|