-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFruitSearching.py
51 lines (40 loc) ยท 2.16 KB
/
FruitSearching.py
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
import openai
import streamlit as st
from streamlit_chat import message
from streamlit_folium import folium_static
import requests
import pandas as pd
import random
import time
import numpy as np
from PIL import Image
import folium
import streamlit.components.v1 as components
from elasticsearch import Elasticsearch
st.image('elasooktic.png', width=150)
with st.sidebar:
# App Gallery ๋ฉ๋ด
choose = st.selectbox("Elasooktic Smart Farm", ["Fruit Searching", "ChatBot", "Fruit Recommendation", "DataFrame"],
index=0,
format_func=lambda x: f"โจ {x}" if x == "Fruit Searching" else f"๐ค {x}" if x == "ChatBot" else f"๐ {x}" if x == "Fruit Recommendation" else f"๐ {x}")
if choose == "Fruit Searching":
# Elasticsearch ํธ์คํธ ๋ฐ ํฌํธ ์ค์
es = Elasticsearch(['ํฌํธ'], http_auth=('ElasticId', 'ElasticPassword'))
# Streamlit ์ ํ๋ฆฌ์ผ์ด์
UI ๊ตฌ์ฑ
st.title('์๋ก์ด ์ ํ์ข
๊ฒ์๐ซง')
st.write('----------------------------')
search_query = st.text_input('์ํ๋ ๊ณผ์ผ์ ์
๋ ฅํ๋ฉด ์ ํ์ข
์ ์ถ์ฒํด๋๋ฆฝ๋๋ค!')
# Elasticsearch์ ์ฟผ๋ฆฌ๋ฅผ ๋ณด๋ด๊ณ ๊ฒฐ๊ณผ๋ฅผ ํ์
if st.button('๊ฒ์'):
res = es.search(index="new_variety", body={"query": {"match": {"type": search_query}}}, size=50)
for hit in res['hits']['hits']:
# ๊ฐ ๊ฒฐ๊ณผ๋ฅผ ์นด๋ ํํ๋ก ํ์
st.markdown(f"## {hit['_source']['title']}", unsafe_allow_html=True)
st.image(hit['_source']['img'], caption="์ด๋ฏธ์ง", use_column_width=True, width=20)
# ๊ธฐ๋ฅ๊ณผ ์ข
๋ฅ ํ์
st.markdown(f"**๊ธฐ๋ฅ:** {hit['_source']['fuction']}", unsafe_allow_html=True)
st.markdown(f"**์ข
๋ฅ:** {hit['_source']['type']}", unsafe_allow_html=True)
# 'see more' ๋ฒํผ ์ถ๊ฐ
with st.expander("View more details!"):
st.write(f"[Download about this fruit!!]({hit['_source']['url']})")
st.write('----------------------------')