dodd869 commited on
Commit
02cfb31
·
verified ·
1 Parent(s): 358ec20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,20 +1,17 @@
1
- import os
2
- from flask import Flask, request, Response, stream_with_context
3
  from huggingface_hub import InferenceClient
 
4
 
5
  app = Flask(__name__)
6
- HF_TOKEN = os.getenv("HF_TOKEN")
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 client.chat_completion(msgs, stream=True):
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__":