Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines7891011121 unmodified line14151617181920212223242526272829303132333435366 unmodified linesHF_TOKEN = os.getenv("HF_TOKEN")client = InferenceClient(model="HuggingFaceH4/zephyr-7b-beta",token=HF_TOKEN1 unmodified line@app.post("/")async def chat(request: Request):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.contentreturn PlainTextResponse(response.strip())6 unmodified lines78910111213141516171 unmodified line1920212223242526272829303132333435363738394041424344456 unmodified linesHF_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.contentreturn PlainTextResponse(response.strip())except Exception as e:return PlainTextResponse(f"Error: {str(e)}")
app.py+29-20