Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456456978912 unmodified lines222324252629272829333031323337383940343536373843444539404142435051444546475 unmodified lines5354556364656656import gradio as grfrom huggingface_hub import InferenceClient
"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""# Initialize the Hugging Face clientclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def respond( message, history: list[tuple[str, str]],12 unmodified lines
messages.append({"role": "user", "content": message})
# Instead of streaming, generate the response and return it once response = ""
for message in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, stream=False # Disable streaming to get a complete response in one go ): token = message.choices[0].delta.content
response += token yield response response += message.choices[0].text # Collect the entire response
# Return the complete response return response
"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""# Create the Gradio interfacedemo = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value="You are a friendly Chatbot.", label="System message"), # Adjust max tokens for concise responses gr.Slider(minimum=1, maximum=512, value=150, step=1, label="Max new tokens"), # Adjusted max tokens value for brevity gr.Slider(minimum=1, maximum=512, value=150, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider( minimum=0.1,5 unmodified lines ],)
if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)
demo.launch()app.py+9-19