Spaces:
Build error
Build error
Update app.py
Browse files4 unmodified lines567891016 unmodified lines2728293031326 unmodified lines3940414243441 unmodified line464748495051524 unmodified linesFor more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(16 unmodified linesresponse = ""try:for message in client.chat_completion(messages,6 unmodified linesif not message or not isinstance(message, dict):continue"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface1 unmodified linedemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(4 unmodified lines56789101116 unmodified lines282930313233346 unmodified lines4142434445464748495051525354555657585960616263646566676869707172737475761 unmodified line787980818283844 unmodified linesFor more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")#client = InferenceClient("unsloth/Llama-3.2-1B-Instruct")def respond(16 unmodified linesresponse = ""try:for message in client.chat_completion(messages,6 unmodified linesif not message or not isinstance(message, dict):continuetry:# Extract content and finish reasoncontent = message.choices[0].delta.contentfinish_reason = message.choices[0].finish_reason# Check if the content is emptyif content.strip() == "":# If the finish reason is 'stop', it's expected and we can break the loopif finish_reason == "stop":print("Stream ended normally.")breakelse:print("Received unexpected empty content, skipping...")continueresponse += contentyield responseexcept (AttributeError, IndexError, KeyError) as e:print(f"Error processing message: {e}")continueexcept Exception as e:print(f"Unexpected error: {e}")yield "An error occurred while generating the response."# Final check if the response is emptyif response.strip() == "":yield "No response generated. Please try again or adjust the settings.""""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface1 unmodified linedemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot. Your name is Juninho.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(
app.py+33-1