AnasHXH commited on
Commit
79bb5a6
1 Parent(s): a2c26d0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load your model
5
+ model_checkpoint = "AnasHXH/Ros_model"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
8
+
9
+ def generate_command(input_text):
10
+ # Tokenize text and convert to model input format
11
+ inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)
12
+ # Generate output from the model
13
+ outputs = model.generate(inputs["input_ids"])
14
+ # Decode the generated tokens to text
15
+ command = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return command
17
+
18
+ # Define your Gradio interface
19
+ iface = gr.Interface(
20
+ fn=generate_command, # the function to wrap
21
+ inputs="text", # the input data type
22
+ outputs="text", # the output data type
23
+ title="Robot Command Generator",
24
+ description="Type in English to get the robot command"
25
+ )
26
+
27
+ # Run the Gradio app
28
+ iface.launch()