aquibali01
commited on
Commit
•
8163806
1
Parent(s):
82e6dbe
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
# Load the model and tokenizer
|
5 |
model_name = "Salesforce/codegen-350M-mono"
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model =
|
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(
|
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
|