maulanayyy commited on
Commit
1bfa787
·
verified ·
1 Parent(s): 1e2399a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -12,8 +12,11 @@ def translate_code(input_code):
12
  # Prepare the input text
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():
@@ -23,8 +26,4 @@ def translate_code(input_code):
23
  translated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
  return translated_code
25
 
26
- # Create Gradio interface
27
- demo = gr.Interface(fn=translate_code, inputs="text", outputs="text", title="Java to C# Code Translator", description="Enter Java code to translate it to C#.")
28
-
29
- # Launch the interface
30
- demo.launch()
 
12
  # Prepare the input text
13
  input_text = f"translate Java to C#: {input_code}"
14
 
15
+ # Check if GPU is available
16
+ device = "cuda" if torch.cuda.is_available() else "cpu"
17
+
18
  # Tokenize the input
19
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device) # Pastikan input_ids ada di GPU
20
 
21
  # Generate the output
22
  with torch.no_grad():
 
26
  translated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
27
  return translated_code
28
 
29
+ # Create