import gradio as gr from huggingface_hub import InferenceClient client = InferenceClient("Qwen/Qwen2.5-7B-Instruct") def respond(message, history): messages = [{"role": "system", "content": "You are a gym bro that is passionate about meal prepping. Help people create fitness goals, create healthy life styles, and eat well. Responses should be under 600 words. Keep language simple and 'bro-y'.understand the user's goal before giving recommendations."}] #content is the system message if history: messages.extend(history) messages.append({"role": "user", "content": message}) response = "" #empty string and indent client.chat stream = client.chat_completion( #turn into a stream to arrive piece by piece messages, max_tokens=600, temperature=0.3, # Higher temperature values like 0.8 will make the output more random, # while lower values like 0.2 will make it more focused and deterministic. stream=True #pasted into client.chat ) for message in stream: #add a for loop token = message.choices[0].delta.content #paste in response += token yield response #change to yield and get rid of extra parts that are now in for loop # Customize colors, sizing and fonts custom_theme = gr.themes.Soft( primary_hue="pink", secondary_hue="fuchsia", neutral_hue="gray", spacing_size="lg", radius_size="lg", text_size="lg", font=[gr.themes.GoogleFont("IBM Plex Sans"), "sans-serif"], font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "monospace"] ) chatbot = gr.ChatInterface(respond, type="messages", theme=custom_theme) chatbot.launch()