Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
import logging
|
|
|
5 |
|
6 |
# λ‘κ·Έ μ€μ
|
7 |
logging.basicConfig(level=logging.INFO)
|
@@ -29,19 +30,33 @@ def analyze_reviews(file_path):
|
|
29 |
df_recent = df[df['리뷰λ μ§'].dt.year >= start_year]
|
30 |
logger.info("μ΅κ·Ό 3λ
λ°μ΄ν° νν°λ§ μλ£")
|
31 |
|
32 |
-
#
|
33 |
-
logger.info("
|
34 |
-
df_recent['
|
35 |
-
|
36 |
-
logger.info("
|
37 |
|
38 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
logger.info("μλ‘μ΄ μνΈ μμ± μμ")
|
40 |
with pd.ExcelWriter(file_path, engine='openpyxl', mode='a') as writer:
|
41 |
-
|
42 |
logger.info("μλ‘μ΄ μνΈ μμ± μλ£")
|
43 |
|
44 |
-
return
|
45 |
except Exception as e:
|
46 |
logger.error(f"λΆμ μ€ μ€λ₯ λ°μ: {e}")
|
47 |
return None
|
@@ -53,10 +68,10 @@ def main():
|
|
53 |
gr.Markdown("### 리뷰 λΆμ μ€νμ΄μ€")
|
54 |
with gr.Row():
|
55 |
file_input = gr.File(label="μλ³Έ μμ
νμΌ μ
λ‘λ", file_types=[".xlsx"])
|
56 |
-
|
57 |
analyze_button = gr.Button("λΆμ")
|
58 |
|
59 |
-
analyze_button.click(fn=analyze_reviews, inputs=file_input, outputs=
|
60 |
|
61 |
demo.launch()
|
62 |
|
|
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
import logging
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
|
7 |
# λ‘κ·Έ μ€μ
|
8 |
logging.basicConfig(level=logging.INFO)
|
|
|
30 |
df_recent = df[df['리뷰λ μ§'].dt.year >= start_year]
|
31 |
logger.info("μ΅κ·Ό 3λ
λ°μ΄ν° νν°λ§ μλ£")
|
32 |
|
33 |
+
# μλ³ λ¦¬λ·° 건μ κ³μ°
|
34 |
+
logger.info("μλ³ λ¦¬λ·° 건μ μ§κ³ μμ")
|
35 |
+
df_recent['λ
μ'] = df_recent['리뷰λ μ§'].dt.to_period('M').astype(str)
|
36 |
+
monthly_review_counts = df_recent.groupby('λ
μ').size().reset_index(name='리뷰건μ')
|
37 |
+
logger.info("μλ³ λ¦¬λ·° 건μ μ§κ³ μλ£")
|
38 |
|
39 |
+
# κ·Έλν μμ±
|
40 |
+
logger.info("κ·Έλν μμ± μμ")
|
41 |
+
plt.figure(figsize=(10, 6))
|
42 |
+
plt.bar(monthly_review_counts['λ
μ'], monthly_review_counts['리뷰건μ'], color='skyblue')
|
43 |
+
plt.xlabel('λ
μ')
|
44 |
+
plt.ylabel('리뷰 건μ')
|
45 |
+
plt.title('μ΅κ·Ό 3λ
μλ³ λ¦¬λ·° 건μ')
|
46 |
+
plt.xticks(rotation=45)
|
47 |
+
graph_path = file_path.replace('.xlsx', '_graph.png')
|
48 |
+
plt.tight_layout()
|
49 |
+
plt.savefig(graph_path)
|
50 |
+
plt.close()
|
51 |
+
logger.info("κ·Έλν μμ± μλ£")
|
52 |
+
|
53 |
+
# μλ‘μ΄ μνΈμ κ·Έλν κ²½λ‘ μ μ₯
|
54 |
logger.info("μλ‘μ΄ μνΈ μμ± μμ")
|
55 |
with pd.ExcelWriter(file_path, engine='openpyxl', mode='a') as writer:
|
56 |
+
monthly_review_counts.to_excel(writer, sheet_name='μλ³ λ¦¬λ·°κ±΄μ', index=False)
|
57 |
logger.info("μλ‘μ΄ μνΈ μμ± μλ£")
|
58 |
|
59 |
+
return graph_path
|
60 |
except Exception as e:
|
61 |
logger.error(f"λΆμ μ€ μ€λ₯ λ°μ: {e}")
|
62 |
return None
|
|
|
68 |
gr.Markdown("### 리뷰 λΆμ μ€νμ΄μ€")
|
69 |
with gr.Row():
|
70 |
file_input = gr.File(label="μλ³Έ μμ
νμΌ μ
λ‘λ", file_types=[".xlsx"])
|
71 |
+
graph_output = gr.File(label="μμ±λ κ·Έλν νμΌ λ€μ΄λ‘λ", type="filepath")
|
72 |
analyze_button = gr.Button("λΆμ")
|
73 |
|
74 |
+
analyze_button.click(fn=analyze_reviews, inputs=file_input, outputs=graph_output)
|
75 |
|
76 |
demo.launch()
|
77 |
|