CoolFace
Apppublic

aosw1148/ShellFE

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
app.py41 linesDownload Raw Back to root
1import streamlit as st
2import requests
3
4# Replace this with the actual URL of your deployed Flask API Hugging Face Space
5API_URL = "https://aosw1148-flask-sample-api.hf.space" 
6
7st.title("🔢 Multiplication Table Generator")
8
9st.markdown("""
10Enter a number below and click "Generate Table" to fetch its 
11multiplication table from the Dockerized Python API backend.
12""")
13
14# Input field for the number 'n'
15number = st.number_input("Enter the number (n):", min_value=1, value=5, step=1)
16
17if st.button("Generate Table"):
18    if number:
19        try:
20            # Construct the full API endpoint URL
21            endpoint = f"{API_URL}/multiplication-table/{int(number)}"
22            
23            # Make the request to the backend API
24            response = requests.get(endpoint)
25            
26            if response.status_code == 200:
27                data = response.json()
28                st.success(f"Multiplication Table for {data['number']}")
29                
30                # Display the table
31                table_data = data['table']
32                
33                # Format the table nicely for Streamlit
34                st.code('\n'.join([f"{k} = {v}" for k, v in table_data.items()]))
35                
36            else:
37                st.error(f"Error calling API: {response.status_code} - {response.json().get('error', 'Unknown error')}")
38        except requests.exceptions.ConnectionError:
39            st.error(f"Could not connect to the backend API at {API_URL}. Please check the URL and ensure the backend Space is running.")
40        except Exception as e:
41            st.error(f"An unexpected error occurred: {e}")