Spaces:
Sleeping
Sleeping
kietnt0603
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
+
|
5 |
+
config = PeftConfig.from_pretrained("kietnt0603/randeng-t5-vta-qa-lora")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("IDEA-CCNL/Randeng-T5-784M-QA-Chinese")
|
7 |
+
model = PeftModel.from_pretrained(model, "kietnt0603/randeng-t5-vta-qa-lora")
|
8 |
+
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("IDEA-CCNL/Randeng-T5-784M-QA-Chinese")
|
10 |
+
|
11 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
12 |
+
|
13 |
+
def predict(text):
|
14 |
+
input_ids = tokenizer(text, max_length=156, return_tensors="pt", padding="max_length", truncation=True).input_ids.to(device)
|
15 |
+
outputs = model.generate(input_ids=input_ids, max_new_tokens=528, do_sample=True)
|
16 |
+
pred = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
|
17 |
+
return pred
|
18 |
+
|
19 |
+
title = 'VTA-QA Demo'
|
20 |
+
article = "Loaded model from https://huggingface.co/kietnt0603/randeng-t5-vta-qa-lora"
|
21 |
+
# Create the Gradio interface
|
22 |
+
iface = gr.Interface(fn=predict,
|
23 |
+
inputs="textbox",
|
24 |
+
outputs="textbox",
|
25 |
+
title=title,
|
26 |
+
article=article)
|
27 |
+
|
28 |
+
# Launch the interface
|
29 |
+
iface.launch()
|