Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678913 unmodified lines232425262728295 unmodified lines3536373839404142434445464748495051526 unmodified lines596061626364import 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"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")13 unmodified linesif val[1]:messages.append({"role": "assistant", "content": val[1]})messages.append({"role": "user", "content": message})response = ""5 unmodified linestop_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = 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(6 unmodified lines],)if __name__ == "__main__":demo.launch()12345613 unmodified lines202122232425262728293031323334353637385 unmodified lines444546474849505152535455565758596061626 unmodified lines6970717273import gradio as grfrom huggingface_hub import InferenceClientclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")13 unmodified linesif val[1]:messages.append({"role": "assistant", "content": val[1]})# Formatting the user input to focus on reasoningformatted_prompt = f"""You are a chatbot that provides reasoning for word sequences but NEVER explicitly states the final answer.Instead, you explain how the words in the sequence relate to each other.Example:User: "Animal, Fruit, Color"Chatbot: "I'm thinking of an animal that's commonly orange, then a fruit that shares the same color, and finally, a color that matches both."Now, explain the reasoning behind: "{message}""""messages.append({"role": "user", "content": formatted_prompt})response = ""5 unmodified linestop_p=top_p,):token = message.choices[0].delta.contentresponse += token# Prevent chatbot from giving away the direct answerif "The answer is" in response or "It is" in response:response = "I can't provide the final answer, but I can explain the reasoning: " + response.split(":")[-1]yield responsedemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a chatbot that provides logical reasoning for sequences of words without explicitly stating the final answer.", 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(6 unmodified lines],)if __name__ == "__main__":demo.launch()
app.py+19-10