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