Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ access_token = os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
|
10 |
login(token=access_token)
|
11 |
|
12 |
# Define model details
|
13 |
-
peft_model_id = "kuyesu22/sunbird-ug-lang-v1.0-llama-2-7b-hf-lora" #
|
14 |
config = PeftConfig.from_pretrained(peft_model_id)
|
15 |
|
16 |
# Load base model and tokenizer
|
@@ -22,6 +22,10 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
22 |
)
|
23 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
24 |
|
|
|
|
|
|
|
|
|
25 |
# Load the LoRA fine-tuned model
|
26 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
27 |
|
@@ -32,7 +36,7 @@ model.eval()
|
|
32 |
def make_inference(english_text):
|
33 |
# Format the prompt based on the language pair
|
34 |
prompt = f"### English:\n{english_text}\n\n### Runyankole:"
|
35 |
-
batch = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True).to(model.device)
|
36 |
|
37 |
# Generate the translation
|
38 |
with torch.no_grad():
|
@@ -56,14 +60,14 @@ def launch_gradio_interface():
|
|
56 |
inputs = gr.components.Textbox(lines=2, label="English Text") # Input text in English
|
57 |
outputs = gr.components.Textbox(label="Translated Runyankole Text") # Output in Runyankole
|
58 |
|
59 |
-
# Launch Gradio app
|
60 |
gr.Interface(
|
61 |
fn=make_inference,
|
62 |
inputs=inputs,
|
63 |
outputs=outputs,
|
64 |
title="Sunbird UG Lang Translator",
|
65 |
description="Translate English to Runyankole using Llama 2 model fine-tuned with LoRA.",
|
66 |
-
).launch()
|
67 |
|
68 |
# Entry point to run the Gradio app
|
69 |
if __name__ == "__main__":
|
|
|
10 |
login(token=access_token)
|
11 |
|
12 |
# Define model details
|
13 |
+
peft_model_id = "kuyesu22/sunbird-ug-lang-v1.0-llama-2-7b-hf-lora" # Your fine-tuned Llama 2 model ID
|
14 |
config = PeftConfig.from_pretrained(peft_model_id)
|
15 |
|
16 |
# Load base model and tokenizer
|
|
|
22 |
)
|
23 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
24 |
|
25 |
+
# Set the tokenizer's padding token
|
26 |
+
if tokenizer.pad_token is None:
|
27 |
+
tokenizer.pad_token = tokenizer.eos_token # Set EOS token as padding if not already defined
|
28 |
+
|
29 |
# Load the LoRA fine-tuned model
|
30 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
31 |
|
|
|
36 |
def make_inference(english_text):
|
37 |
# Format the prompt based on the language pair
|
38 |
prompt = f"### English:\n{english_text}\n\n### Runyankole:"
|
39 |
+
batch = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=256).to(model.device)
|
40 |
|
41 |
# Generate the translation
|
42 |
with torch.no_grad():
|
|
|
60 |
inputs = gr.components.Textbox(lines=2, label="English Text") # Input text in English
|
61 |
outputs = gr.components.Textbox(label="Translated Runyankole Text") # Output in Runyankole
|
62 |
|
63 |
+
# Launch Gradio app with public sharing link enabled
|
64 |
gr.Interface(
|
65 |
fn=make_inference,
|
66 |
inputs=inputs,
|
67 |
outputs=outputs,
|
68 |
title="Sunbird UG Lang Translator",
|
69 |
description="Translate English to Runyankole using Llama 2 model fine-tuned with LoRA.",
|
70 |
+
).launch(share=True) # Set `share=True` to create a public link
|
71 |
|
72 |
# Entry point to run the Gradio app
|
73 |
if __name__ == "__main__":
|