Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,48 @@
|
|
| 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 |
-
#
|
| 13 |
-
|
| 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
|
| 16 |
-
df['Year-Month'] = df['Review Date'].astype(str).str.slice(0, 7)
|
| 17 |
-
df['Year'] = df['Review Date'].astype(str).str.slice(0, 4)
|
| 18 |
-
df['Month'] = df['Review Date'].astype(str).str.slice(5, 7)
|
| 19 |
-
df['Day'] = df['Review Date'].astype(str).str.slice(8, 10)
|
| 20 |
-
df['Option1'] = df['Option'].str.split(" / ").str[0] # 1์ฐจ ์ต์
๋ง ์ถ์ถ
|
| 21 |
-
df['Review Length'] = df['Review'].str.len() # ์ถ๊ฐ๋ ๋ถ๋ถ: ๋ฆฌ๋ทฐ ๊ธธ์ด ๊ณ์ฐ
|
| 22 |
-
return df
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# ๊ธด ๊ธ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํจ์ ์ ์
|
| 29 |
def long_text_result(file):
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
def chatbot_response(input_text):
|
| 37 |
response = f"์ฑ๋ด ์๋ต: {input_text}"
|
| 38 |
return response
|
|
|
|
| 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 |
+
import os
|
| 7 |
|
| 8 |
+
# API ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
| 9 |
+
client = Client("https://ssboost-excel-ra-vector-db-test1.hf.space/--replicas/q77r3/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# ์์
๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ค๋ ํจ์ (API ์ฌ์ฉ์ผ๋ก ํ์ ์์ด์ง)
|
| 12 |
+
# def read_excel_data(file):
|
| 13 |
+
# df = pd.read_excel(BytesIO(file), usecols="B, C, D, E", skiprows=1, names=["Review Date", "Option", "Review", "ReviewScore"])
|
| 14 |
+
# df['Review Date'] = pd.to_datetime(df['Review Date']).dt.tz_localize(None).dt.date
|
| 15 |
+
# df['Year-Month'] = df['Review Date'].astype(str).str.slice(0, 7)
|
| 16 |
+
# df['Year'] = df['Review Date'].astype(str).str.slice(0, 4)
|
| 17 |
+
# df['Month'] = df['Review Date'].astype(str).str.slice(5, 7)
|
| 18 |
+
# df['Day'] = df['Review Date'].astype(str).str.slice(8, 10)
|
| 19 |
+
# df['Option1'] = df['Option'].str.split(" / ").str[0] # 1์ฐจ ์ต์
๋ง ์ถ์ถ
|
| 20 |
+
# df['Review Length'] = df['Review'].str.len() # ์ถ๊ฐ๋ ๋ถ๋ถ: ๋ฆฌ๋ทฐ ๊ธธ์ด ๊ณ์ฐ
|
| 21 |
+
# return df
|
| 22 |
|
| 23 |
# ๊ธด ๊ธ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํจ์ ์ ์
|
| 24 |
def long_text_result(file):
|
| 25 |
+
# ์์ ํ์ผ ์์ฑ ๋ฐ ์ ์ฅ
|
| 26 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp_file:
|
| 27 |
+
tmp_file.write(file)
|
| 28 |
+
tmp_file_path = tmp_file.name
|
| 29 |
+
|
| 30 |
+
# API ํธ์ถ์ ํตํด ๋ถ์, ์ ์ฅ, ๋ฒกํฐ DB ๋ฐ ์ธ๋ฑ์ฑ ์งํ
|
| 31 |
+
result = client.predict(
|
| 32 |
+
tmp_file_path,
|
| 33 |
+
100,
|
| 34 |
+
10,
|
| 35 |
+
api_name="/analyze_and_initialize_db"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# ์์ ํ์ผ ์ญ์
|
| 39 |
+
os.remove(tmp_file_path)
|
| 40 |
+
|
| 41 |
+
# ๋ถ์ ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
| 42 |
+
analysis = "์ํ์ ์ฅ๋จ์ 10๊ฐ์ง ๋ถ์ ๊ฒฐ๊ณผ:\n" + str(result)
|
| 43 |
+
return analysis
|
| 44 |
|
| 45 |
+
# ์ฑ๋ด ์๋ต ์์ฑ
|
| 46 |
def chatbot_response(input_text):
|
| 47 |
response = f"์ฑ๋ด ์๋ต: {input_text}"
|
| 48 |
return response
|