Skip to content

Commit a67334d

Browse files
authored
Add files via upload
1 parent 33b4e7d commit a67334d

File tree

7 files changed

+1370
-1
lines changed

7 files changed

+1370
-1
lines changed

14-Streamlit/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import streamlit as st
2+
import pandas as pd
3+
import numpy as np
4+
5+
## Title of the aplication
6+
st.title("Hello Streamlit")
7+
8+
## Diplay a Simple Text
9+
st.write("This is a imple text")
10+
11+
##create a simple Dataframe
12+
13+
df = pd.DataFrame({
14+
'first column': [1, 2, 3, 4],
15+
'second column': [10, 20, 30, 40]
16+
})
17+
18+
19+
## Display the Dataframe
20+
st.write("Here is the dataframe")
21+
st.write(df)
22+
23+
24+
##create a line chart
25+
26+
chart_data=pd.DataFrame(
27+
np.random.randn(20,3),columns=['a','b','c']
28+
)
29+
st.line_chart(chart_data)

14-Streamlit/classification.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import streamlit as st
2+
import pandas as pd
3+
from sklearn.datasets import load_iris
4+
from sklearn.ensemble import RandomForestClassifier
5+
6+
@st.cache_data
7+
def load_data():
8+
iris = load_iris()
9+
df = pd.DataFrame(iris.data, columns=iris.feature_names)
10+
df['species'] = iris.target
11+
return df, iris.target_names
12+
13+
df,target_names=load_data()
14+
15+
model=RandomForestClassifier()
16+
model.fit(df.iloc[:,:-1],df['species'])
17+
18+
st.sidebar.title("Input Features")
19+
sepal_length = st.sidebar.slider("Sepal length", float(df['sepal length (cm)'].min()), float(df['sepal length (cm)'].max()))
20+
sepal_width = st.sidebar.slider("Sepal width", float(df['sepal width (cm)'].min()), float(df['sepal width (cm)'].max()))
21+
petal_length = st.sidebar.slider("Petal length", float(df['petal length (cm)'].min()), float(df['petal length (cm)'].max()))
22+
petal_width = st.sidebar.slider("Petal width", float(df['petal width (cm)'].min()), float(df['petal width (cm)'].max()))
23+
24+
input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
25+
26+
## PRediction
27+
prediction = model.predict(input_data)
28+
predicted_species = target_names[prediction[0]]
29+
30+
st.write("Prediction")
31+
st.write(f"The predicted species is: {predicted_species}")
32+

14-Streamlit/sampledata.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
,Name,Age,City
2+
0,John,28,New York
3+
1,Jane,24,Los Angeles
4+
2,Jake,35,Chicago
5+
3,Jill,40,Houston

14-Streamlit/streamlit.ipynb

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### Introduction to Streamlit\n",
8+
"Streamlit is an open-source app framework for Machine Learning and Data Science projects. It allows you to create beautiful web applications for your machine learning and data science projects with simple Python scripts."
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"metadata": {
15+
"vscode": {
16+
"languageId": "plaintext"
17+
}
18+
},
19+
"outputs": [],
20+
"source": []
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {
26+
"vscode": {
27+
"languageId": "plaintext"
28+
}
29+
},
30+
"outputs": [],
31+
"source": []
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"metadata": {
37+
"vscode": {
38+
"languageId": "plaintext"
39+
}
40+
},
41+
"outputs": [],
42+
"source": []
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {
48+
"vscode": {
49+
"languageId": "plaintext"
50+
}
51+
},
52+
"outputs": [],
53+
"source": []
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {
59+
"vscode": {
60+
"languageId": "plaintext"
61+
}
62+
},
63+
"outputs": [],
64+
"source": []
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {
70+
"vscode": {
71+
"languageId": "plaintext"
72+
}
73+
},
74+
"outputs": [],
75+
"source": []
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {
81+
"vscode": {
82+
"languageId": "plaintext"
83+
}
84+
},
85+
"outputs": [],
86+
"source": []
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {
92+
"vscode": {
93+
"languageId": "plaintext"
94+
}
95+
},
96+
"outputs": [],
97+
"source": []
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"metadata": {
103+
"vscode": {
104+
"languageId": "plaintext"
105+
}
106+
},
107+
"outputs": [],
108+
"source": []
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"metadata": {
114+
"vscode": {
115+
"languageId": "plaintext"
116+
}
117+
},
118+
"outputs": [],
119+
"source": []
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"metadata": {
125+
"vscode": {
126+
"languageId": "plaintext"
127+
}
128+
},
129+
"outputs": [],
130+
"source": []
131+
}
132+
],
133+
"metadata": {
134+
"language_info": {
135+
"name": "python"
136+
}
137+
},
138+
"nbformat": 4,
139+
"nbformat_minor": 2
140+
}

14-Streamlit/widgets.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import streamlit as st
2+
import pandas as pd
3+
4+
st.title("Streamlit Text Input")
5+
6+
name=st.text_input("Enter your name:")
7+
8+
9+
age=st.slider("Select your age:",0,100,25)
10+
11+
st.write(f"Your age is {age}.")
12+
13+
options = ["Python", "Java", "C++", "JavaScript"]
14+
choice = st.selectbox("Choose your favorite language:", options)
15+
st.write(f"You selected {choice}.")
16+
17+
if name:
18+
st.write(f"Hello, {name}")
19+
20+
21+
data = {
22+
"Name": ["John", "Jane", "Jake", "Jill"],
23+
"Age": [28, 24, 35, 40],
24+
"City": ["New York", "Los Angeles", "Chicago", "Houston"]
25+
}
26+
27+
df = pd.DataFrame(data)
28+
df.to_csv("sampledata.csv")
29+
st.write(df)
30+
31+
32+
uploaded_file=st.file_uploader("Choose a CSV file",type="csv")
33+
34+
if uploaded_file is not None:
35+
df=pd.read_csv(uploaded_file)
36+
st.write(df)
37+

0 commit comments

Comments
 (0)