import gradio as gr from transformers import pipeline pipe = pipeline( "text-generation", model="Simon0900/personalized-fitness-coach-JSON" ) def respond(message, history, system_message, max_tokens, temperature, top_p): prompt = system_message.strip() + "\n\n" # Limit history (VERY important) history = history[-4:] for user_msg, bot_msg in history: prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n" prompt += f"User: {message}\nAssistant:" result = pipe( prompt, max_new_tokens=min(max_tokens, 4096), # prevent runaway generation temperature=temperature, top_p=top_p, do_sample=True, return_full_text=False, eos_token_id=pipe.tokenizer.eos_token_id, # important stop signal ) return result[0]["generated_text"] chatbot = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value="""You are a fitness expert. You will create a workout plan in JSON-schema, based on the given user description. Strictly use the following format:\n\nJSON-schematic:\n{\n \"goal\": ,\n \"intensity\": ,\n \"workout_equipment\": ,\n \"workout_days\": ,\n \"time_per_workout\":