SUHHHH commited on
Commit
0fc9dd5
ยท
verified ยท
1 Parent(s): d7f6eb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
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,