import gradio as gr from transformers import AutoTokenizer, AutoModelForSeq2SeqLM # Load model model_name = "google/flan-t5-base" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSeq2SeqLM.from_pretrained(model_name) def diagnose(component, symptom): prompt = f"What could be the issue if the {component} is showing this symptom: {symptom}?" inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=100) return tokenizer.decode(outputs[0], skip_special_tokens=True) # Gradio UI interface = gr.Interface( fn=diagnose, inputs=[ gr.Dropdown(["Motor", "Battery", "Sensor", "Controller", "Actuator"], label="Component"), gr.Textbox(lines=2, placeholder="Describe the symptom (e.g., not moving, overheating)...", label="Symptom") ], outputs="text", title="Robot Fault Diagnosis (Gen AI)", description="Select a robot component and describe the symptom to get possible fault diagnosis using Generative AI." ) interface.launch()