Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines345678912 unmodified lines222324252627282930313233343536378 unmodified lines4647484950515253541 unmodified line565758596061626 unmodified lines69707172732 unmodified linesclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],12 unmodified lines# 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 = ""8 unmodified linestoken = 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 response1 unmodified linedemo = 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(server_name="0.0.0.0", server_port=7860)2 unmodified lines34567812 unmodified lines2122232425262728293031328 unmodified lines4142434445464748491 unmodified line515253545556576 unmodified lines6465666768692 unmodified linesclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],12 unmodified lines# Formatting the user input to focus on reasoningformatted_prompt = f"""You are a chatbot that provides a structured, concise sequence without long explanations.For example:"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."Do NOT provide long descriptive explanations.Now, explain the reasoning behind: "{message}""""messages.append({"role": "user", "content": formatted_prompt})response = ""8 unmodified linestoken = message.choices[0].delta.contentresponse += token# Limit the response to concise explanationsif len(response.split()) > 50: # Prevent long explanationsresponse = "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."yield response1 unmodified linedemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a chatbot that provides a structured, concise sequence without long explanations.", 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(server_name="0.0.0.0", server_port=7860)
app.py+9-13