Spaces:
Build error
Build error
add files
Browse files- app.py +39 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
device = "cuda:0"
|
| 6 |
+
|
| 7 |
+
model = pipeline("text-classification", "iknow-lab/ko-flan-zero-v0-0731", device=device)
|
| 8 |
+
model.tokenizer.truncation_side = 'left'
|
| 9 |
+
|
| 10 |
+
def inference(input, instruction, labels):
|
| 11 |
+
instruction = f"{input} [SEP] {instruction}"
|
| 12 |
+
inputs = model.tokenizer([instruction] * len(labels), labels, truncation=True, padding=True, return_tensors="pt").to(device)
|
| 13 |
+
|
| 14 |
+
scores = model.model(**inputs).logits.squeeze(1).softmax(-1).tolist()
|
| 15 |
+
output = dict(zip(labels, scores))
|
| 16 |
+
|
| 17 |
+
print(instruction)
|
| 18 |
+
print(output)
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def greet(content, instruction, labels):
|
| 23 |
+
labels = labels.split(",")
|
| 24 |
+
output = inference(content, instruction, labels)
|
| 25 |
+
return output
|
| 26 |
+
|
| 27 |
+
content = gr.TextArea(label="μ
λ ₯ λ΄μ©")
|
| 28 |
+
instruction = gr.Textbox(label="μ§μλ¬Έ")
|
| 29 |
+
labels = gr.Textbox(label="λΌλ²¨(μΌνλ‘ κ΅¬λΆ)")
|
| 30 |
+
|
| 31 |
+
examples = [
|
| 32 |
+
["μμ μλ μ£Όλ§λ§λ€ κ·Ήμ₯μ λλ¬κ°λλ° μμλ μ’ μκ°λ νΈμ΄μμ", "λκΈ μ£Όμ λ₯Ό λΆλ₯νμΈμ", "μν,λλΌλ§,κ²μ,μμ€"],
|
| 33 |
+
["μΈμ²λ° KTXμ κ΄λ ¨νβμ‘λμ 볡ν©νμΉμΌν°κ°βμ¬μ€μβ무μ°,βλ¨μ μ² λΒ·λ²μ€ μμ£Ό νμΉμμ€λ‘βλ§λ€μ΄μ§λ€.βμ΄ λλ¬Έμ μΈμ²μμ μΈμ²λ° KTXβκΈ°μ μ μ΅μ»€μμ€μΈ 볡ν©νμΉμΌν°λ₯Ό ν΅ν μΈκ·Όβμ§μβκ²½μ βνμ±νλ₯Όβμ΄λ€λΈλ€λ κ³νμ μ°¨μ§μ΄ λΆκ°νΌνλ€.", "κ²½μ μ κΈμ μ μΈ λ΄μ€μΈκ°μ?", "μ,μλμ"],
|
| 34 |
+
["λ§μ§λ§μλ kν 곡μ°λ³΄κ³ μ’μ μΆμ΅ λ¨μμΌλ©΄ μ’κ² λ€μ","μμ€μ΄ ν¬ν¨λμ΄μλμ?", "μμ€μ΄ μμ΅λλ€,μμ€μ΄ μμ΅λλ€"],
|
| 35 |
+
]
|
| 36 |
+
gr.Interface(fn=greet,
|
| 37 |
+
inputs=[content, instruction, labels],
|
| 38 |
+
outputs=gr.Label(),
|
| 39 |
+
examples=examples).launch() # server_name="0.0.0.0",server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|