Manikeerthan01 commited on
Commit
2b6a591
·
verified ·
1 Parent(s): 39fc11f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -38
app.py CHANGED
@@ -1,48 +1,35 @@
1
  import streamlit as st
2
- import numpy as np
3
- import matplotlib.pyplot as plt
 
4
 
5
  # Title of the app
6
- st.title("Mathematical Function Plotter")
7
-
8
- # Input for the function
9
- function = st.text_input("Enter a mathematical function (use 'x' as the variable):", "sin(x)")
10
-
11
- # Input for the range
12
- x_min = st.number_input("Enter the minimum value of x:", -10)
13
- x_max = st.number_input("Enter the maximum value of x:", 10)
14
- step = st.number_input("Enter the step size:", 0.1)
15
-
16
- # Button to plot the function
17
- if st.button("Plot"):
18
- try:
19
- # Define the x range
20
- x = np.arange(x_min, x_max, step)
21
-
22
- # Safely evaluate the function
23
- y = eval(function, {"x": x, "np": np})
24
-
25
- # Create the plot
26
- plt.figure()
27
- plt.plot(x, y, label=f'y = {function}')
28
- plt.xlabel('x')
29
- plt.ylabel('y')
30
- plt.title('Plot of the function')
31
- plt.legend()
32
- plt.grid(True)
33
-
34
- # Display the plot
35
- st.pyplot(plt)
36
- except Exception as e:
37
- st.error(f"Error in plotting the function: {e}")
38
 
39
  # Instructions for the user
40
  st.sidebar.title("Instructions")
41
  st.sidebar.info(
42
  """
43
- Enter a mathematical function in the text input box using 'x' as the variable (e.g., 'sin(x)', 'cos(x)', 'x**2').
44
- Specify the range for 'x' (minimum, maximum, and step size).
45
- Click the "Plot" button to visualize the function.
46
  """
47
  )
48
-
 
1
  import streamlit as st
2
+ import requests
3
+ from PIL import Image
4
+ from io import BytesIO
5
 
6
  # Title of the app
7
+ st.title("Profile Picture Generator")
8
+
9
+ # Input for the name
10
+ name = st.text_input("Enter your name:")
11
+
12
+ # Button to get the profile picture
13
+ if st.button("Get Profile Picture"):
14
+ if name:
15
+ # Generate URL for the profile picture
16
+ url = f"https://robohash.org/{name}.png"
17
+
18
+ # Fetch the image from the URL
19
+ response = requests.get(url)
20
+ if response.status_code == 200:
21
+ img = Image.open(BytesIO(response.content))
22
+ st.image(img, caption=f'Profile Picture for {name}', use_column_width=True)
23
+ else:
24
+ st.error("Error fetching the image. Please try again.")
25
+ else:
26
+ st.error("Please enter a name.")
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  # Instructions for the user
29
  st.sidebar.title("Instructions")
30
  st.sidebar.info(
31
  """
32
+ 1. Enter your name in the text input box.
33
+ 2. Click the "Get Profile Picture" button to generate and view a profile picture associated with the entered name.
 
34
  """
35
  )