Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines78910111213141516171 unmodified line19202122171819202122232425262728293031323334353623242526272829303132333435363738394041424344456 unmodified lines
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN: print("HF_TOKEN NOT FOUND")else: print("HF_TOKEN LOADED")
client = InferenceClient( model="HuggingFaceH4/zephyr-7b-beta", token=HF_TOKEN1 unmodified line
@app.post("/")async def chat(request: Request): try: data = await request.json() user_message = data.get("message", "")
messages = [ {"role": "system", "content": "Answer briefly and clearly."}, {"role": "user", "content": user_message} ]
response = ""
for chunk in client.chat_completion( messages=messages, max_tokens=100, temperature=0.7, stream=True ): if chunk.choices and chunk.choices[0].delta.content: response += chunk.choices[0].delta.content
return PlainTextResponse(response.strip()) data = await request.json() user_message = data.get("message", "")
messages = [ {"role": "system", "content": "Answer briefly and clearly."}, {"role": "user", "content": user_message} ]
response = ""
for chunk in client.chat_completion( messages=messages, max_tokens=100, temperature=0.7, stream=True ): if chunk.choices and chunk.choices[0].delta.content: response += chunk.choices[0].delta.content
return PlainTextResponse(response.strip())
except Exception as e: return PlainTextResponse(f"Error: {str(e)}")app.py+29-20