aquibali01 commited on
Commit
8163806
1 Parent(s): 82e6dbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
 
4
  # Load the model and tokenizer
5
  model_name = "Salesforce/codegen-350M-mono"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
 
9
  # Function to translate Python code to JavaScript
10
  def translate_code(python_code):
11
- inputs = tokenizer(python_code, return_tensors="pt", max_length=512, truncation=True)
12
- outputs = model.generate(**inputs, max_length=512, num_beams=5, early_stopping=True)
13
- translated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
  return translated_code
15
 
16
  # Gradio interface
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
  # Load the model and tokenizer
5
  model_name = "Salesforce/codegen-350M-mono"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
  # Function to translate Python code to JavaScript
10
  def translate_code(python_code):
11
+ inputs = tokenizer(python_code, return_tensors="pt")
12
+ outputs = model.generate(inputs["input_ids"], max_length=150, num_return_sequences=1)
13
+ translated_code = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
14
  return translated_code
15
 
16
  # Gradio interface