Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +74 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from collections import defaultdict
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
uploaded_file = st.file_uploader("Excelファイルを選択してください", type=["xlsx"])
|
7 |
+
|
8 |
+
if uploaded_file is not None:
|
9 |
+
df = pd.read_excel(uploaded_file)
|
10 |
+
|
11 |
+
st.sidebar.write("ファイルの内容:")
|
12 |
+
st.sidebar.dataframe(df)
|
13 |
+
dct = defaultdict(list)
|
14 |
+
column_names = df.columns.tolist()
|
15 |
+
for idx, row in df.iterrows():
|
16 |
+
key = (row['品番'], row['外径'])
|
17 |
+
dct[key].append((row['値段'], row['在庫数']))
|
18 |
+
|
19 |
+
def find_screws(diameter, weight):
|
20 |
+
try:
|
21 |
+
weight = np.float64(weight)
|
22 |
+
key = (diameter, weight)
|
23 |
+
return dct[key]
|
24 |
+
except ValueError:
|
25 |
+
return 0
|
26 |
+
|
27 |
+
if "messages" not in st.session_state:
|
28 |
+
# 辞書形式で定義
|
29 |
+
st.session_state["messages"] = []
|
30 |
+
|
31 |
+
for message in st.session_state.messages:
|
32 |
+
with st.chat_message(message["role"]):
|
33 |
+
st.markdown(message["content"])
|
34 |
+
|
35 |
+
if prompt := st.chat_input("品番と外径を改行区切りで入力してください"):
|
36 |
+
with st.chat_message("user"):
|
37 |
+
st.markdown(prompt)
|
38 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
39 |
+
|
40 |
+
L = prompt.split('\n')
|
41 |
+
|
42 |
+
if(len(L) < 2):
|
43 |
+
response = "要素数が少ないです。 \n・品番 \n・外径 \nの順番に入力してください"
|
44 |
+
print(response)
|
45 |
+
elif(len(L) > 2):
|
46 |
+
response = "要素数が多いです。 \n・品番 \n・外径 \nの順番に入力してください"
|
47 |
+
print(response)
|
48 |
+
else:
|
49 |
+
p_id,diameter = L[0], L[1]
|
50 |
+
if diameter and p_id:
|
51 |
+
result = find_screws(p_id,diameter)
|
52 |
+
if result == 0:
|
53 |
+
response = f"""
|
54 |
+
品番 : {p_id} \n
|
55 |
+
外径 : {diameter} \n
|
56 |
+
は正しい入力形式ではありません。(カンマや空白などが入っていない確認してください) \n
|
57 |
+
"""
|
58 |
+
elif result:
|
59 |
+
response = f"""
|
60 |
+
見つかりました。 \n
|
61 |
+
品番 : {p_id} \n
|
62 |
+
外径 : {diameter} \n
|
63 |
+
価格 : {result[0][1]} \n
|
64 |
+
在庫 : {result[0][0]} \n
|
65 |
+
"""
|
66 |
+
else:
|
67 |
+
response = f"""
|
68 |
+
品番 : {p_id} \n
|
69 |
+
外径 : {diameter} \n
|
70 |
+
に該当するものは見つかりませんでした。 \n
|
71 |
+
"""
|
72 |
+
with st.chat_message("assistant"):
|
73 |
+
st.markdown(response)
|
74 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
openpyxl
|