Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
4 |
sentiment = pipeline("sentiment-analysis")
|
5 |
|
|
|
6 |
def get_sentiment(์
๋ ฅ):
|
7 |
-
#
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
model, tokenizer = get_pipe()
|
40 |
-
|
41 |
-
def ask_question(input_):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
gr.Interface(fn=ask_question, inputs="text", outputs="text", title="KoAlpaca-355M", description="ํ๊ตญ์ด๋ก ์ง๋ฌธํ์ธ์.").launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# ๊ฐ์ฑ ๋ถ์ ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
5 |
sentiment = pipeline("sentiment-analysis")
|
6 |
|
7 |
+
# ์ฌ์ฉ์ ์
๋ ฅ์ ๋ํ ๊ฐ์ฑ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ํจ์
|
8 |
def get_sentiment(์
๋ ฅ):
|
9 |
+
# ๊ฐ์ฑ ๋ถ์ ์คํ
|
10 |
+
result = sentiment(์
๋ ฅ)
|
11 |
+
# ๊ฒฐ๊ณผ ํฌ๋งทํ
๋ฐ ๋ฐํ
|
12 |
+
return result[0]
|
13 |
+
|
14 |
+
# Gradio ์ฑ ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=get_sentiment, # ์คํํ ํจ์
|
17 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="์ฌ๊ธฐ์ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์..."), # ์
๋ ฅ๋ ์ค์
|
18 |
+
outputs="json", # ์ถ๋ ฅ ํํ
|
19 |
+
clear_on_submit=True, # ์ ์ถ ํ ์
๋ ฅ๋ ํด๋ฆฌ์ด
|
20 |
+
title="ํ
์คํธ ๊ฐ์ฑ ๋ถ์", # UI ์ ๋ชฉ
|
21 |
+
description="ํ
์คํธ๋ฅผ ์
๋ ฅํ๊ณ ์ ์ถ ๋ฒํผ์ ํด๋ฆญํ์ฌ ๊ฐ์ฑ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ธ์." # UI ์ค๋ช
|
22 |
+
)
|
23 |
+
|
24 |
+
# Gradio ์ฑ ์คํ
|
25 |
+
iface.launch()
|
26 |
+
|
27 |
+
# import gradio as gr
|
28 |
+
# from transformers import pipeline
|
29 |
+
|
30 |
+
# sentiment = pipeline("sentiment-analysis")
|
31 |
+
|
32 |
+
# def get_sentiment(์
๋ ฅ):
|
33 |
+
# # from transformers import AutoTokenizer, AutoModelForCausalLM
|
34 |
+
# # model_name = "heegyu/koalpaca-355m"
|
35 |
+
# # tokenizer = AutoTokenizer.from_pretrained(model_name)
|
36 |
+
# # tokenizer.truncation_side = "right"
|
37 |
+
# # model = AutoModelForCausalLM.from_pretrained(model_name)
|
38 |
+
# return sentiment(์
๋ ฅ)
|
39 |
+
|
40 |
+
# def get_response(output):
|
41 |
+
# context = f"<usr>{context}\n<sys>"
|
42 |
+
# inputs = tokenizer(
|
43 |
+
# context,
|
44 |
+
# truncation=True,
|
45 |
+
# max_length=512,
|
46 |
+
# return_tensors="pt")
|
47 |
|
48 |
+
# generation_args = dict(
|
49 |
+
# max_length=256,
|
50 |
+
# min_length=64,
|
51 |
+
# eos_token_id=2,
|
52 |
+
# do_sample=True,
|
53 |
+
# top_p=1.0,
|
54 |
+
# early_stopping=True
|
55 |
+
# )
|
56 |
+
|
57 |
+
# outputs = model.generate(**inputs, **generation_args)
|
58 |
+
# response = tokenizer.decode(outputs[0])
|
59 |
+
# print(context)
|
60 |
+
# print(response)
|
61 |
+
# response = response[len(context):].replace("</s>", "")
|
62 |
+
|
63 |
+
# return response
|
64 |
+
|
65 |
+
# model, tokenizer = get_pipe()
|
66 |
+
|
67 |
+
# def ask_question(input_):
|
68 |
+
# response = get_response(tokenizer, model, input_)
|
69 |
+
# return response
|
70 |
+
|
71 |
+
# gr.Interface(fn=ask_question, inputs="text", outputs="text", title="KoAlpaca-355M", description="ํ๊ตญ์ด๋ก ์ง๋ฌธํ์ธ์.").launch()
|