Spaces:
Runtime error
Runtime error
Commit
•
57179e0
1
Parent(s):
12d8064
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from peft import get_peft_config, get_peft_model, PeftModel, PeftConfig, LoraConfig, TaskType
|
3 |
+
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
+
|
6 |
+
# huggingface hub model id
|
7 |
+
model_id="xavierbarbier/flan-t5-small-ameli_qa_10k"
|
8 |
+
|
9 |
+
|
10 |
+
# load model from the hub
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
12 |
+
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
14 |
+
|
15 |
+
max_target_length = 512
|
16 |
+
|
17 |
+
def greet(input_text):
|
18 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
19 |
+
outputs = model.generate(input_ids = input_ids, max_length = max_target_length)
|
20 |
+
answer = tokenizer.decode(outputs[0]).replace("<pad> ","").replace("</s>","")
|
21 |
+
|
22 |
+
return answer
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=greet, inputs=["text"],
|
25 |
+
outputs="text")
|
26 |
+
iface.launch(share=True)
|