-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
205 lines (171 loc) · 6.64 KB
/
Copy pathapp.py
File metadata and controls
205 lines (171 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import streamlit as st
from anthropic import Anthropic
from dotenv import load_dotenv
import os
load_dotenv()
# ✅ Streamlit Cloud secrets থেকে key নাও
try:
# Streamlit Cloud এ
api_key = st.secrets["ANTHROPIC_API_KEY"]
except:
# Local এ .env থেকে
load_dotenv()
api_key = os.getenv("ANTHROPIC_API_KEY")
client = Anthropic(api_key=api_key)
# Page Config
st.set_page_config(
page_title="Saif's Kids Store AI",
page_icon="🛍️",
layout="wide"
)
# Header
st.title("🛍️ Saif's Kids Store")
st.subheader("All-in-One AI Dashboard for Product, Pricing & Customer Support")
st.divider()
# Sidebar
with st.sidebar:
st.header("📋 Menu")
page = st.selectbox(
"কী করতে চাও?",
["💬 AI Chat", "📝 Content Generator", "💰 Price Checker"]
)
st.divider()
st.markdown("**📦 Available Products:**")
st.markdown("🧩 Bangladesh Map Puzzle — ৳450")
st.markdown("🎨 Magic Drawing Board — ৳350")
st.markdown("🧠 Flash Cards — ৳250")
# ✅ Page 1 — AI Chat
if page == "💬 AI Chat":
st.header("💬 AI Chat Assistant")
#initial Response
st.markdown("💡 Try asking:")
with st.chat_message("user"):
st.write("Flash Card এর দাম কত?")
with st.chat_message("assistant"):
st.write("Flash Cards এর দাম **২৫০ টাকা।**")
st.write("এটি বাচ্চাদের জন্য একটি দুর্দান্ত পণ্য যা শেখার প্রক্রিয়াকে আরও মজাদার করে তোলে। আপনি কি এটি অর্ডার করতে আগ্রহী? 😊")
# Chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Show chat history
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.write(msg["content"])
# Input
if prompt := st.chat_input("প্রশ্ন করো..."):
#initial Response
# User message
st.session_state.messages.append(
{"role": "user", "content": prompt}
)
with st.chat_message("user"):
st.write(prompt)
# AI response
with st.chat_message("assistant"):
with st.spinner("ভাবছি..."):
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=300,
system="""তুমি Saif's Kids Store এর AI Assistant।
বাংলায় উত্তর দাও।
Products:
- Bangladesh Map Puzzle: ৪৫০ টাকা
- Magic Drawing Board: ৩৫০ টাকা
- Flash Cards: ২৫০ টাকা""",
messages=st.session_state.messages
)
ai_response = response.content[0].text
st.write(ai_response)
st.session_state.messages.append(
{"role": "assistant", "content": ai_response}
)
# ✅ Page 2 — Content Generator
elif page == "📝 Content Generator":
st.header("📝 Product Content Generator")
col1, col2 = st.columns(2)
with col1:
product_name = st.selectbox(
"Product বেছে নাও:",
["Bangladesh Map Puzzle", "Magic Drawing Board", "Flash Cards"]
)
price = st.number_input("দাম (টাকা):", min_value=0, value=450)
target = st.text_input(
"Target Customer:",
value="শিশুদের অভিভাবক"
)
with col2:
content_type = st.multiselect(
"কী বানাবে?",
["Facebook Caption", "Product Description", "Hashtags"],
default=["Facebook Caption", "Product Description"]
)
if st.button("🚀 Generate করো!", type="primary"):
with st.spinner("AI content বানাচ্ছে..."):
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=500,
system="তুমি F-commerce marketing expert। বাংলায় লেখো।",
messages=[{
"role": "user",
"content": f"""
পণ্য: {product_name}
দাম: {price} টাকা
টার্গেট: {target}
বানাও: {', '.join(content_type)}
"""
}]
)
st.success("✅ Content তৈরি হয়েছে!")
st.markdown(response.content[0].text)
# Download button
st.download_button(
label="📥 Download করো",
data=response.content[0].text,
file_name=f"{product_name}_content.txt",
mime="text/plain"
)
# ✅ Page 3 — Price Checker
elif page == "💰 Price Checker":
st.header("💰 AI Price Checker")
col1, col2 = st.columns(2)
with col1:
check_product = st.text_input(
"Product নাম:",
value="Flash Cards"
)
my_price = st.number_input(
"তোমার দাম (টাকা):",
min_value=0,
value=250
)
with col2:
st.info("💡 AI তোমার দাম analyze করবে এবং suggestion দেবে!")
if st.button("🔍 Check করো!", type="primary"):
with st.spinner("Analyzing..."):
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=300,
system="তুমি Bangladesh e-commerce pricing expert। বাংলায় advice দাও।",
messages=[{
"role": "user",
"content": f"""
Product: {check_product}
আমার দাম: {my_price} টাকা
Competitor দাম:
- Bangladesh Map Puzzle: ৪০০-৫০০ টাকা
- Magic Drawing Board: ৩০০-৪০০ টাকা
- Flash Cards: ২০০-৩০০ টাকা
বলো:
1. দাম ঠিক আছে?
2. Suggestion কী?
"""
}]
)
# Show result with metrics
st.divider()
m1, m2, m3 = st.columns(3)
m1.metric("Product", check_product)
m2.metric("তোমার দাম", f"৳{my_price}")
m3.metric("Market Range", "৳200-500")
st.markdown("### 🤖 AI Analysis:")
st.markdown(response.content[0].text)