Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import
|
4 |
|
5 |
# Load the model and tokenizer
|
6 |
-
model_name = "maulanayyy/code_translation_codet5"
|
7 |
-
tokenizer =
|
8 |
-
model =
|
9 |
|
10 |
# Function to perform inference
|
11 |
def translate_code(input_code):
|
@@ -13,7 +13,7 @@ def translate_code(input_code):
|
|
13 |
input_text = f"translate Java to C#: {input_code}"
|
14 |
|
15 |
# Tokenize the input
|
16 |
-
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
17 |
|
18 |
# Generate the output
|
19 |
with torch.no_grad():
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
4 |
|
5 |
# Load the model and tokenizer
|
6 |
+
model_name = "maulanayyy/code_translation_codet5" # Ganti dengan nama model yang benar
|
7 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
8 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name).to("cuda")
|
9 |
|
10 |
# Function to perform inference
|
11 |
def translate_code(input_code):
|
|
|
13 |
input_text = f"translate Java to C#: {input_code}"
|
14 |
|
15 |
# Tokenize the input
|
16 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda") # Pastikan input_ids ada di GPU
|
17 |
|
18 |
# Generate the output
|
19 |
with torch.no_grad():
|