Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import random
|
@@ -78,6 +80,31 @@ def generate_response(prompt, reference_text, max_tokens, temperature, top_p, mo
|
|
78 |
"""
|
79 |
return response_html
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
82 |
with gr.Blocks() as demo:
|
83 |
gr.Markdown("## ์ธ์ด ๋ชจ๋ธ ํ๋กฌํํธ ํ๋ ์ด๊ทธ๋ผ์ด๋")
|
@@ -95,6 +122,19 @@ with gr.Blocks() as demo:
|
|
95 |
generate_button = gr.Button("์๋ต ์์ฑ")
|
96 |
response_output = gr.HTML(label="์์ฑ๋ ์๋ต")
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
# ๋ฒํผ ํด๋ฆญ ์ ์๋ต ์์ฑ
|
99 |
generate_button.click(
|
100 |
generate_response,
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import pipeline
|
4 |
from huggingface_hub import InferenceClient
|
5 |
import os
|
6 |
import random
|
|
|
80 |
"""
|
81 |
return response_html
|
82 |
|
83 |
+
# ๋ฆฌ๋ทฐ ํ์ผ ์ฒ๋ฆฌ ํจ์
|
84 |
+
def process_reviews(file):
|
85 |
+
df = pd.read_excel(file.name)
|
86 |
+
|
87 |
+
if 'review' not in df.columns:
|
88 |
+
return "๋ฆฌ๋ทฐ ํ์ผ์ 'review' ์ด์ด ์์ต๋๋ค. ์ฌ๋ฐ๋ฅธ ํ์ผ์ ์
๋ก๋ํ์ธ์."
|
89 |
+
|
90 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
91 |
+
reviews = df['review'].tolist()
|
92 |
+
|
93 |
+
# ๊ฐ์ฑ ๋ถ์ ์ํ
|
94 |
+
sentiments = sentiment_analyzer(reviews)
|
95 |
+
|
96 |
+
# ๊ธ์ ๋ฐ ๋ถ์ ๋ฆฌ๋ทฐ ํํฐ๋ง
|
97 |
+
positive_reviews = [r['review'] for r, s in zip(reviews, sentiments) if s['label'] == 'POSITIVE'][:10]
|
98 |
+
negative_reviews = [r['review'] for r, s in zip(reviews, sentiments) if s['label'] == 'NEGATIVE'][:10]
|
99 |
+
|
100 |
+
# ๋ถ์ ๊ฒฐ๊ณผ ์์ฝ
|
101 |
+
total_reviews = len(reviews)
|
102 |
+
positive_count = len([s for s in sentiments if s['label'] == 'POSITIVE'])
|
103 |
+
negative_count = len([s for s in sentiments if s['label'] == 'NEGATIVE'])
|
104 |
+
analysis_summary = f"์ด ๋ฆฌ๋ทฐ ์: {total_reviews}, ๊ธ์ ๋ฆฌ๋ทฐ ์: {positive_count}, ๋ถ์ ๋ฆฌ๋ทฐ ์: {negative_count}"
|
105 |
+
|
106 |
+
return "\n".join(positive_reviews), "\n".join(negative_reviews), analysis_summary
|
107 |
+
|
108 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
109 |
with gr.Blocks() as demo:
|
110 |
gr.Markdown("## ์ธ์ด ๋ชจ๋ธ ํ๋กฌํํธ ํ๋ ์ด๊ทธ๋ผ์ด๋")
|
|
|
122 |
generate_button = gr.Button("์๋ต ์์ฑ")
|
123 |
response_output = gr.HTML(label="์์ฑ๋ ์๋ต")
|
124 |
|
125 |
+
# ๋ฆฌ๋ทฐ ํ์ผ ์
๋ก๋ ๋ฉ๋ด ์ถ๊ฐ
|
126 |
+
file_input = gr.File(label="๋ฆฌ๋ทฐ ์์
ํ์ผ ์
๋ก๋")
|
127 |
+
positive_reviews_output = gr.Textbox(label="๋ํ ๊ธ์ ๋ฆฌ๋ทฐ 10๊ฐ", lines=10, interactive=False)
|
128 |
+
negative_reviews_output = gr.Textbox(label="๋ํ ๋ถ์ ๋ฆฌ๋ทฐ 10๊ฐ", lines=10, interactive=False)
|
129 |
+
analysis_output = gr.Textbox(label="๋ถ์ ๊ฒฐ๊ณผ", interactive=False)
|
130 |
+
|
131 |
+
# ๋ฆฌ๋ทฐ ํ์ผ ์ฒ๋ฆฌ ๋ฒํผ
|
132 |
+
file_input.change(
|
133 |
+
process_reviews,
|
134 |
+
inputs=file_input,
|
135 |
+
outputs=[positive_reviews_output, negative_reviews_output, analysis_output]
|
136 |
+
)
|
137 |
+
|
138 |
# ๋ฒํผ ํด๋ฆญ ์ ์๋ต ์์ฑ
|
139 |
generate_button.click(
|
140 |
generate_response,
|