Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10주차 #9

Open
clghks opened this issue Nov 28, 2023 · 3 comments
Open

10주차 #9

clghks opened this issue Nov 28, 2023 · 3 comments

Comments

@clghks
Copy link
Collaborator

clghks commented Nov 28, 2023

No description provided.

@Ting-Kim
Copy link

마지막 실습 레포

@62hoon99
Copy link

실습 레포지토리

@62hoon99
Copy link

62hoon99 commented Nov 28, 2023

import streamlit as st
import requests

def autocomplete(query):
    # 여기에 사용할 자동완성 API의 엔드포인트 및 기타 정보를 추가하세요
    # 예: autocomplete_url = "https://api.example.com/autocomplete?q=" + query
    autocomplete_url = "http://localhost:8080/restaurants/auto-completion?q=" + query
    response = requests.get(autocomplete_url)
    results = response.json() if response.status_code == 200 else []
    return results

def search(query):
    # 여기에 사용할 자동완성 API의 엔드포인트 및 기타 정보를 추가하세요
    # 예: autocomplete_url = "https://api.example.com/autocomplete?q=" + query
    autocomplete_url = "http://localhost:8080/restaurants/search?page=0&size=10&q=" + query
    response = requests.get(autocomplete_url)
    results = response.json() if response.status_code == 200 else []
    return results

def main():
    st.title("검색 서비스")        

    # 텍스트 입력 상자
    search_query = st.text_input("검색어를 입력하세요.")
    
    if st.button("검색하기"):
        search_result = search(search_query)
        st.write(search_result)

    # 검색어가 입력되면 자동완성 API 호출 및 결과 표시
    if search_query:
        st.write("검색어: ", search_query)
        autocomplete_results = autocomplete(search_query)

        # 자동완성 결과를 선택할 수 있는 selectbox 추가
        selected_result = st.selectbox("자동완성 결과:", autocomplete_results, index=0)

        # 사용자가 결과를 선택하면 입력 상자에 적용
        if selected_result:
            # st.text_input 대신 st.button을 사용하여 텍스트 클릭 감지
            search_result = search(selected_result)
            st.write(search_result)
            

if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants