Spaces:
Runtime error
Runtime error
| 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) | |