Thermostatic
commited on
Commit
•
b41d8ac
1
Parent(s):
4fcbc99
Init app
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
import spaces
|
4 |
+
|
5 |
+
# Set the model and tokenizer
|
6 |
+
model_name = "meta-llama/Meta-Llama-3-70B-Instruct"
|
7 |
+
lora_name = "Thermostatic/Llama-3-NeuralTranslate-Instructions-70b-v0.1-lora"
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
lora_adapter = model.load_adapter(lora_name, with_head=False)
|
11 |
+
model.to('cuda')
|
12 |
+
|
13 |
+
@spaces.GPU
|
14 |
+
def translate(input_text):
|
15 |
+
input_ids = tokenizer.encode(f"Translate the following text from English to Spanish: {input_text}", return_tensors="pt")
|
16 |
+
response = model.generate(input_ids, adapter_name=lora_name, max_length=1024)
|
17 |
+
response_text = tokenizer.decode(response[0], skip_special_tokens=True)
|
18 |
+
return f"Translated text: {response_text}"
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
with gr.Row():
|
22 |
+
input_text = gr.Textbox(label="Enter a message to translate:")
|
23 |
+
submit = gr.Button("Translate")
|
24 |
+
output = gr.Textbox(label="Translated text:")
|
25 |
+
|
26 |
+
submit.click(fn=translate, inputs="input_text", outputs="output")
|
27 |
+
|
28 |
+
demo.launch()
|