Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
-
from flask import Flask, request, Response, stream_with_context
|
| 3 |
from huggingface_hub import InferenceClient
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
-
|
| 7 |
-
if not HF_TOKEN:
|
| 8 |
-
raise RuntimeError("HF_TOKEN environment variable not set")
|
| 9 |
-
|
| 10 |
-
client = InferenceClient(token=HF_TOKEN, model="deepseek-ai/DeepSeek-V3.1")
|
| 11 |
|
| 12 |
@app.route("/chat", methods=["POST"])
|
| 13 |
def chat():
|
| 14 |
msgs = request.json["messages"]
|
| 15 |
def gen():
|
| 16 |
-
for d in
|
| 17 |
yield d.encode()
|
|
|
|
| 18 |
return Response(gen(), mimetype="text/plain")
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
from flask import Flask, request, Response
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import os, json
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
+
cli = InferenceClient(token=os.getenv("HF_TOKEN"), model="Qwen/Qwen3-32B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@app.route("/chat", methods=["POST"])
|
| 9 |
def chat():
|
| 10 |
msgs = request.json["messages"]
|
| 11 |
def gen():
|
| 12 |
+
for d in cli.chat_completion(msgs, stream=True):
|
| 13 |
yield d.encode()
|
| 14 |
+
yield b"" # sentinel so client sees EOF
|
| 15 |
return Response(gen(), mimetype="text/plain")
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|