Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,61 @@ st.set_page_config(page_title="Dr. Radha: The Agro-Homeopath", page_icon="🌿")
|
|
20 |
# Set persistent storage path
|
21 |
PERSISTENT_DIR = "vector_db"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Define image paths
|
24 |
HEADER_IMAGE = "i1.jpg" # Organic farming landscape
|
25 |
SIDE_IMAGE = "i2.JPG" # Medicinal plants/herbs
|
@@ -53,24 +108,9 @@ images = [
|
|
53 |
)
|
54 |
]
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
.carousel {
|
60 |
-
width: 100%;
|
61 |
-
height: 400px; /* Set your desired fixed height */
|
62 |
-
}
|
63 |
-
|
64 |
-
.carousel img {
|
65 |
-
width: 100%;
|
66 |
-
height: 400px; /* Same height as container */
|
67 |
-
object-fit: cover; /* Maintains aspect ratio while filling container */
|
68 |
-
object-position: center; /* Centers the image */
|
69 |
-
}
|
70 |
-
</style>
|
71 |
-
""", unsafe_allow_html=True)
|
72 |
-
|
73 |
-
carousel(items=images)
|
74 |
|
75 |
def initialize_vector_db():
|
76 |
if os.path.exists(PERSISTENT_DIR) and os.listdir(PERSISTENT_DIR):
|
@@ -101,42 +141,12 @@ def initialize_vector_db():
|
|
101 |
|
102 |
system_prompt = """You are an expert organic farming consultant with specialization in Agro-Homeopathy. When providing suggestions and remedies:
|
103 |
1. Always specify medicine potency as 6c unless the uploaded text mentions some other value explicitly
|
104 |
-
|
105 |
-
|
106 |
"""
|
107 |
|
108 |
api_key1 = os.getenv("api_key")
|
109 |
|
110 |
-
#st.set_page_config(page_title="Dr. Radha: The Agro-Homeopath", page_icon="🌿", layout="wide")
|
111 |
-
|
112 |
-
# Add custom CSS for image styling
|
113 |
-
st.markdown("""
|
114 |
-
<style>
|
115 |
-
.stApp {
|
116 |
-
background-color: #1B4D3E !important;
|
117 |
-
color: white !important;
|
118 |
-
}
|
119 |
-
.stTextInput>div>div>input {
|
120 |
-
color: black !important;
|
121 |
-
background-color: rgba(255,255,255,0.1) !important;
|
122 |
-
}
|
123 |
-
.stButton>button {
|
124 |
-
color: white !important;
|
125 |
-
background-color: yellow !important;
|
126 |
-
}
|
127 |
-
.custom-image {
|
128 |
-
border-radius: 15px;
|
129 |
-
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
|
130 |
-
margin: 10px 0;
|
131 |
-
transition: transform 0.3s ease;
|
132 |
-
}
|
133 |
-
.custom-image:hover {
|
134 |
-
transform: scale(1.02);
|
135 |
-
}
|
136 |
-
</style>
|
137 |
-
""", unsafe_allow_html=True)
|
138 |
-
|
139 |
-
|
140 |
st.title("🌿 Dr. Radha: AI-Powered Organic Farming Consultant")
|
141 |
st.subheader("Specializing in Agro-Homeopathy | Free Consultation")
|
142 |
|
@@ -273,105 +283,32 @@ fallback_chain = LLMChain(llm=llm, prompt=fallback_prompt)
|
|
273 |
|
274 |
chat_container = st.container()
|
275 |
|
276 |
-
st.
|
277 |
-
|
278 |
-
|
279 |
-
color: red;
|
280 |
-
}
|
281 |
-
/* Maintain color on hover and focus */
|
282 |
-
.stButton > button:hover {
|
283 |
-
color: red;
|
284 |
-
}
|
285 |
-
.stButton > button:focus {
|
286 |
-
color: red;
|
287 |
-
}
|
288 |
-
</style>
|
289 |
-
""", unsafe_allow_html=True)
|
290 |
-
|
291 |
-
with st.form(key='query_form'):
|
292 |
-
query = st.text_input("Ask your question:", value="")
|
293 |
-
submit_button = st.form_submit_button(label='Submit')
|
294 |
-
|
295 |
-
if submit_button and query:
|
296 |
-
with st.spinner("Generating response..."):
|
297 |
-
result = qa({"query": query})
|
298 |
-
if result['result'].strip() == "":
|
299 |
-
fallback_result = fallback_chain.run(query)
|
300 |
-
response = fallback_result
|
301 |
-
else:
|
302 |
-
response = result['result']
|
303 |
-
|
304 |
-
col1, col2 = st.columns([1, 10])
|
305 |
-
with col1:
|
306 |
-
st.image(human_image, width=80)
|
307 |
-
with col2:
|
308 |
-
st.markdown(f"{query}")
|
309 |
-
col1, col2 = st.columns([1, 10])
|
310 |
-
with col1:
|
311 |
-
st.image(robot_image, width=80)
|
312 |
with col2:
|
313 |
-
st.
|
314 |
-
|
315 |
-
st.markdown("---")
|
316 |
-
st.session_state["query"] = ""
|
317 |
-
|
318 |
-
# Add this before the form section in your main code
|
319 |
-
st.markdown("---")
|
320 |
|
321 |
-
# Define your image paths
|
322 |
-
carousel_images = [
|
323 |
-
"i1.jpg",
|
324 |
-
"i2.JPG",
|
325 |
-
"i3.JPG",
|
326 |
-
]
|
327 |
|
328 |
-
|
329 |
-
st.
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
# # Check if interval has passed
|
352 |
-
# current_time = time.time()
|
353 |
-
# if current_time - st.session_state.carousel_time > interval:
|
354 |
-
# st.session_state.carousel_idx = (st.session_state.carousel_idx + 1) % len(image_paths)
|
355 |
-
# st.session_state.carousel_time = current_time
|
356 |
-
|
357 |
-
# # Create three columns
|
358 |
-
# cols = st.columns(3)
|
359 |
-
|
360 |
-
# # Calculate indices for three images
|
361 |
-
# num_images = len(image_paths)
|
362 |
-
# indices = [
|
363 |
-
# (st.session_state.carousel_idx + i) % num_images
|
364 |
-
# for i in range(3)
|
365 |
-
# ]
|
366 |
-
|
367 |
-
# # Display images
|
368 |
-
# for idx, col in enumerate(cols):
|
369 |
-
# with col:
|
370 |
-
# st.image(
|
371 |
-
# image_paths[indices[idx]],
|
372 |
-
# use_container_width=True,
|
373 |
-
# caption=f"Image {indices[idx]+1}"
|
374 |
-
# )
|
375 |
-
|
376 |
-
# # Replace the previous carousel call with:
|
377 |
-
# create_auto_rotating_carousel(carousel_images, interval=3)
|
|
|
20 |
# Set persistent storage path
|
21 |
PERSISTENT_DIR = "vector_db"
|
22 |
|
23 |
+
# Add custom CSS to maintain consistent image height
|
24 |
+
st.markdown("""
|
25 |
+
<style>
|
26 |
+
.stApp {
|
27 |
+
background-color: #1B4D3E !important;
|
28 |
+
color: white !important;
|
29 |
+
max-width: 100%;
|
30 |
+
padding: 1rem;
|
31 |
+
}
|
32 |
+
|
33 |
+
/* Make carousel images equal size */
|
34 |
+
.carousel {
|
35 |
+
width: 100%;
|
36 |
+
height: 400px;
|
37 |
+
}
|
38 |
+
|
39 |
+
.carousel img {
|
40 |
+
width: 100%;
|
41 |
+
height: 400px;
|
42 |
+
object-fit: cover;
|
43 |
+
object-position: center;
|
44 |
+
}
|
45 |
+
|
46 |
+
/* Style the form and button */
|
47 |
+
.stButton > button {
|
48 |
+
color: black !important;
|
49 |
+
background-color: yellow !important;
|
50 |
+
width: 100%;
|
51 |
+
padding: 0.5rem;
|
52 |
+
}
|
53 |
+
|
54 |
+
/* Make text input and output full width */
|
55 |
+
.stTextInput > div > div > input {
|
56 |
+
color: black !important;
|
57 |
+
background-color: rgba(255,255,255,0.1) !important;
|
58 |
+
width: 100%;
|
59 |
+
}
|
60 |
+
|
61 |
+
/* Style the chat container */
|
62 |
+
.chat-container {
|
63 |
+
width: 100%;
|
64 |
+
max-width: 1200px;
|
65 |
+
margin: 0 auto;
|
66 |
+
padding: 1rem;
|
67 |
+
}
|
68 |
+
|
69 |
+
/* Make title and headers full width */
|
70 |
+
.stTitle, .stHeader {
|
71 |
+
width: 100%;
|
72 |
+
text-align: center;
|
73 |
+
margin: 1rem 0;
|
74 |
+
}
|
75 |
+
</style>
|
76 |
+
""", unsafe_allow_html=True)
|
77 |
+
|
78 |
# Define image paths
|
79 |
HEADER_IMAGE = "i1.jpg" # Organic farming landscape
|
80 |
SIDE_IMAGE = "i2.JPG" # Medicinal plants/herbs
|
|
|
108 |
)
|
109 |
]
|
110 |
|
111 |
+
carousel_container = st.container()
|
112 |
+
with carousel_container:
|
113 |
+
carousel(items=images, height=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
def initialize_vector_db():
|
116 |
if os.path.exists(PERSISTENT_DIR) and os.listdir(PERSISTENT_DIR):
|
|
|
141 |
|
142 |
system_prompt = """You are an expert organic farming consultant with specialization in Agro-Homeopathy. When providing suggestions and remedies:
|
143 |
1. Always specify medicine potency as 6c unless the uploaded text mentions some other value explicitly
|
144 |
+
2. Provide comprehensive diagnosis and treatment advice along with organic farming best practices applicable in the given context
|
145 |
+
3. Base recommendations on homeopathic and organic farming principles
|
146 |
"""
|
147 |
|
148 |
api_key1 = os.getenv("api_key")
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
st.title("🌿 Dr. Radha: AI-Powered Organic Farming Consultant")
|
151 |
st.subheader("Specializing in Agro-Homeopathy | Free Consultation")
|
152 |
|
|
|
283 |
|
284 |
chat_container = st.container()
|
285 |
|
286 |
+
with st.form(key='query_form', clear_on_submit=True):
|
287 |
+
query = st.text_area("Ask your question:", height=100)
|
288 |
+
col1, col2, col3 = st.columns([1,3,1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
with col2:
|
290 |
+
submit_button = st.form_submit_button(label='Submit')
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
+
if submit_button and query:
|
294 |
+
chat_container = st.container()
|
295 |
+
with chat_container:
|
296 |
+
with st.spinner("Generating response..."):
|
297 |
+
result = qa({"query": query})
|
298 |
+
if result['result'].strip() == "":
|
299 |
+
response = fallback_chain.run(query)
|
300 |
+
else:
|
301 |
+
response = result['result']
|
302 |
+
|
303 |
+
st.markdown("---")
|
304 |
+
cols = st.columns([1,10])
|
305 |
+
with cols[0]:
|
306 |
+
st.image(human_image, width=80)
|
307 |
+
with cols[1]:
|
308 |
+
st.markdown(f"**Question:** {query}")
|
309 |
+
|
310 |
+
cols = st.columns([1,10])
|
311 |
+
with cols[0]:
|
312 |
+
st.image(robot_image, width=80)
|
313 |
+
with cols[1]:
|
314 |
+
st.markdown(f"**Answer:** {response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|