Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from io import BytesIO
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
-
from gradio_client import Client
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
client = Client("https://ssboost-excel-ra-vector-db-test1.hf.space/--replicas/q77r3/")
|
| 9 |
-
|
| 10 |
-
# ์์
๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ค๋ ํจ์
|
| 11 |
def read_excel_data(file):
|
| 12 |
df = pd.read_excel(BytesIO(file), usecols="B, C, D, E", skiprows=1, names=["Review Date", "Option", "Review", "ReviewScore"])
|
| 13 |
df['Review Date'] = pd.to_datetime(df['Review Date']).dt.tz_localize(None).dt.date
|
|
@@ -19,37 +21,18 @@ def read_excel_data(file):
|
|
| 19 |
df['Review Length'] = df['Review'].str.len() # ์ถ๊ฐ๋ ๋ถ๋ถ: ๋ฆฌ๋ทฐ ๊ธธ์ด ๊ณ์ฐ
|
| 20 |
return df
|
| 21 |
|
| 22 |
-
# ๊ธด ๋ฆฌ๋ทฐ๋ฅผ ์ถ์ถํ๋ ํจ์
|
| 23 |
def extract_longest_reviews(df):
|
| 24 |
longest_reviews = df.groupby('ReviewScore').apply(lambda x: x.nlargest(100, 'Review Length', keep='all')).reset_index(drop=True)
|
| 25 |
-
return longest_reviews.drop(columns=['Review Length', 'Year-Month', 'Year', 'Month', 'Day', 'Option1'])
|
| 26 |
|
| 27 |
-
# ๊ธด ๊ธ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํจ์
|
| 28 |
def long_text_result(file):
|
| 29 |
df = read_excel_data(file)
|
| 30 |
longest_reviews = extract_longest_reviews(df)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp_file:
|
| 34 |
-
df.to_excel(tmp_file.name, index=False)
|
| 35 |
-
tmp_file_path = tmp_file.name
|
| 36 |
-
|
| 37 |
-
# API ํธ์ถ์ ํตํด ๋ถ์, ์ ์ฅ, ๋ฒกํฐ DB ๋ฐ ์ธ๋ฑ์ฑ ์งํ
|
| 38 |
-
result = client.predict(
|
| 39 |
-
tmp_file_path,
|
| 40 |
-
100,
|
| 41 |
-
10,
|
| 42 |
-
api_name="/analyze_and_initialize_db"
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
# ์์ ํ์ผ ์ญ์
|
| 46 |
-
os.remove(tmp_file_path)
|
| 47 |
-
|
| 48 |
-
# ๋ถ์ ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
| 49 |
-
analysis = "์ํ์ ์ฅ๋จ์ 10๊ฐ์ง ๋ถ์ ๊ฒฐ๊ณผ:\n" + str(result)
|
| 50 |
-
return analysis
|
| 51 |
|
| 52 |
-
#
|
| 53 |
def chatbot_response(input_text):
|
| 54 |
response = f"์ฑ๋ด ์๋ต: {input_text}"
|
| 55 |
return response
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
import openpyxl
|
| 3 |
+
from openpyxl.chart import BarChart, Reference, PieChart
|
| 4 |
+
from openpyxl.chart.label import DataLabelList
|
| 5 |
+
from openpyxl.utils.dataframe import dataframe_to_rows
|
| 6 |
+
from datetime import datetime
|
| 7 |
from io import BytesIO
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
import tempfile
|
| 11 |
|
| 12 |
+
# Read excel data for review analysis
|
|
|
|
|
|
|
|
|
|
| 13 |
def read_excel_data(file):
|
| 14 |
df = pd.read_excel(BytesIO(file), usecols="B, C, D, E", skiprows=1, names=["Review Date", "Option", "Review", "ReviewScore"])
|
| 15 |
df['Review Date'] = pd.to_datetime(df['Review Date']).dt.tz_localize(None).dt.date
|
|
|
|
| 21 |
df['Review Length'] = df['Review'].str.len() # ์ถ๊ฐ๋ ๋ถ๋ถ: ๋ฆฌ๋ทฐ ๊ธธ์ด ๊ณ์ฐ
|
| 22 |
return df
|
| 23 |
|
|
|
|
| 24 |
def extract_longest_reviews(df):
|
| 25 |
longest_reviews = df.groupby('ReviewScore').apply(lambda x: x.nlargest(100, 'Review Length', keep='all')).reset_index(drop=True)
|
| 26 |
+
return longest_reviews.drop(columns=['Review Length', 'Year-Month', 'Year', 'Month', 'Day', 'Option1', 'Option2']) # ์ญ์ ๋ ์ด๋ค
|
| 27 |
|
| 28 |
+
# ๊ธด ๊ธ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํจ์ ์ ์
|
| 29 |
def long_text_result(file):
|
| 30 |
df = read_excel_data(file)
|
| 31 |
longest_reviews = extract_longest_reviews(df)
|
| 32 |
+
text_result = longest_reviews.to_string(index=False)
|
| 33 |
+
return text_result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# ์๋ก์ด ํญ ์ธํฐํ์ด์ค ์ ์
|
| 36 |
def chatbot_response(input_text):
|
| 37 |
response = f"์ฑ๋ด ์๋ต: {input_text}"
|
| 38 |
return response
|