File size: 1,927 Bytes
86ec184
 
 
 
aa4d80e
 
 
86ec184
 
 
 
 
aa4d80e
86ec184
 
aa4d80e
86ec184
 
 
aa4d80e
86ec184
 
 
 
 
aa4d80e
86ec184
 
 
 
aa4d80e
86ec184
 
aa4d80e
86ec184
 
 
aa4d80e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86ec184
 
aa4d80e
86ec184
 
aa4d80e
86ec184
 
aa4d80e
86ec184
aa4d80e
86ec184
aa4d80e
 
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
import streamlit as st
import requests

def wide_space_default():
    """
    Configures the Streamlit page layout to wide and sets the page title.
    """
    st.set_page_config(
        layout="wide",
        page_title="Search Free Courses",
    )

# Apply default layout settings
wide_space_default()

# Custom CSS styling for Streamlit components
css_for_text = """
<style>
    p, li, strong, ul {
        font-size: 20px !important;
    }
    h1 {
        font-size: 28px;
    }
    .text {
        font-size: 22px !important;
    }
</style>
"""

# Applying custom CSS
st.markdown(css_for_text, unsafe_allow_html=True)

# Header for the application
st.header("Analytics Vidya Free Courses", anchor=False)

def sending_keyword(keyword):
    """
    Sends the keyword to the FastAPI endpoint and retrieves the course search results.

    Args:
        keyword (str): The keyword to search for courses.

    Returns:
        str: The response from the API containing the search results.
    """
    try:
        response = requests.get("http://0.0.0.0:8000/get_courses", params={"keyword": keyword}).json()
        return response['results']
    except Exception as e:
        return f"Error: Unable to connect to the API. Details: {e}"

# Default response message
response = "This is a search engine project created for Analytics Vidya Free Courses. " \
           "The project helps users to type any keyword related to the free courses they are looking for."

# Sidebar components
with st.sidebar:
    keyword = st.text_input("Enter course keyword:")
    submit_button = st.button("Search Courses")

    if keyword or submit_button:
        st.write(f"Your entered keyword is: {keyword}")
        st.snow()

# Fetch and display response if a keyword is entered or button is pressed
if keyword or submit_button:
    response = sending_keyword(keyword)

# Display the response
st.markdown(response, unsafe_allow_html=True)