Spaces:
Sleeping
Sleeping
| 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\": <workout goal>,\n \"intensity\": <intensity level>,\n \"workout_equipment\": <workout equipment>,\n \"workout_days\": <workout days>,\n \"time_per_workout\": <time per workout>,\n \"limitations\": <limitations>,\n \"days\": [\n {\n \"day\": <day of week>,\n \"focus\": <muscle groups>,\n \"estimated_duration_min\": <estimated duration>,\n \"warmup_exercise\": <warmup exercise>,\n \"exercises\": [\n {\n \"name\": <name of exercise>,\n \"muscle_group\": <muscle group>,\n \"instructions\": <instructions>,\n \"sets\": <number of sets>,\n \"reps\": <number of reps>,\n \"rest_seconds\": <rest duration>\n }\n OR\n {\n \"name\": <name of exercise>,\n \"muscle_group\": \"cardio\",\n \"instructions\": <instructions>,\n \"duration_min\": <duration>\n }\n ]\n }\n ]\n}\n\nRules:\n- Warmup must differ from exercises\n- At least 3 exercises per day\n- No repeating exercises on consecutive days\n- Optimize for recovery and variation\n- Spread out the workout days over a week\n- Not every exercise has to use the equipment\n- Cardio exercises do not have to use the equipment\n- Respond only with valid JSON using double quotes\n | |
| """), | |
| gr.Slider(1, 4096, value=4096, step=1), | |
| gr.Slider(0.1, 2.0, value=0.7, step=0.1), | |
| gr.Slider(0.1, 1.0, value=0.95, step=0.05), | |
| ], | |
| ) | |
| demo = chatbot | |
| demo.launch() |