AnasHXH/ROS2
1
1import gradio as gr2from transformers import AutoTokenizer, AutoModelForSeq2SeqLM3 4# Load your model5model_checkpoint = "AnasHXH/Ros_model"6tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)7model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)8 9def generate_command(input_text):10 # Tokenize text and convert to model input format11 inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)12 # Generate output from the model13 outputs = model.generate(inputs["input_ids"])14 # Decode the generated tokens to text15 command = tokenizer.decode(outputs[0], skip_special_tokens=True)16 return command17 18# Define your Gradio interface19iface = gr.Interface(20 fn=generate_command, # the function to wrap21 inputs="text", # the input data type22 outputs="text", # the output data type23 title="Robot Command Generator",24 description="Type in English to get the robot command"25)26 27# Run the Gradio app28iface.launch()