Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions IrisPrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def inputFeatures():
'sepal_width': sepal_width,
'petal_length': petal_length,
'petal_width': petal_width}
features = pd.DataFrame(data, index=[0])
return features
return pd.DataFrame(data, index=[0])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function inputFeatures refactored with the following changes:


def main():
st.markdown(html_temp, unsafe_allow_html=True)
Expand Down
3 changes: 1 addition & 2 deletions StreamlitApps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def pencilsketch(inp_img):
img_gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
img_invert = cv2.bitwise_not(img_gray)
img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
final_img = dodgeV2(img_gray, img_smoothing)
return(final_img)
return dodgeV2(img_gray, img_smoothing)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pencilsketch refactored with the following changes:



st.title("PencilSketcher App")
Expand Down
18 changes: 9 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def videoUserDefined(src: str, width="100%", height=315):
# @cache
@st.cache
def load_data():
df = pd.read_csv("https://github.com/SurendraRedd/StreamlitProjects/raw/master/lang.csv")
return df
return pd.read_csv(
"https://github.com/SurendraRedd/StreamlitProjects/raw/master/lang.csv"
)
Comment on lines -49 to +51

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function load_data refactored with the following changes:



# In[ ]:
Expand Down Expand Up @@ -75,7 +76,7 @@ def main():

"""
st.markdown(html_temp,unsafe_allow_html=True)
st.markdown('<i class="material-icons">{}</i>'.format("people"), unsafe_allow_html=True)
st.markdown('<i class="material-icons">people</i>', unsafe_allow_html=True)
Comment on lines -78 to +79

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.latex(r'''
... a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} =
Expand All @@ -92,8 +93,7 @@ def main():
my_table = st.table(df1)

df = st.cache(pd.read_csv)("https://github.com/SurendraRedd/StreamlitProjects/raw/master/lang.csv")
is_check = st.checkbox("Display Data")
if is_check:
if is_check := st.checkbox("Display Data"):
st.write(df)

st.write('Dataframe example')
Expand All @@ -116,7 +116,7 @@ def main():

data = {'1':"True",'2':"True",'3':"False"}
st.json(data)

# Exception handling
st.exception("IndexError('list out of index')")

Expand Down Expand Up @@ -163,7 +163,7 @@ def main():
["SamaraSimhaReddy", "Simha",
"NarasimhaNaidu", "Legend"])


# Will only run once if already cached
df = load_data()
st.write(df)
Expand All @@ -187,7 +187,7 @@ def main():
with st.echo():
text = 's="Happy Learning!" for i in range(0,10): print(s)'
st.write(text)


#Image opening
#img = Image.open("download.jfif") #open the image stored in specified location
Expand Down Expand Up @@ -230,7 +230,7 @@ def main():
for percent_complete in range(100):
time.sleep(0.1)
my_bar.progress(percent_complete + 1)

with st.spinner('Wait for it...'):
time.sleep(5)
st.success('Done!')
Expand Down
100 changes: 45 additions & 55 deletions sketcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ def imageConversion(inputImage):
grayScaleImg = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
invertImg = cv2.bitwise_not(grayScaleImg)
smoothImg = cv2.GaussianBlur(invertImg, (21,21),sigmaX=0, sigmaY=0)
finalImg = dodgeV2(grayScaleImg,smoothImg)
return finalImg
return dodgeV2(grayScaleImg,smoothImg)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function imageConversion refactored with the following changes:


def main():
# Documentation - Main Function to process
# Title of the web page
st.title("Convert an image in to pencil sketch")
st.subheader("This application has options to select the image either from sidebar or in mainpage.")
html_temp = """
st.title("Convert an image in to pencil sketch")
st.subheader("This application has options to select the image either from sidebar or in mainpage.")
html_temp = """
<body style="background-color:red;">
<div style="background-color:teal ;padding:10px">
<h2 style="color:white;text-align:center;">Image to Pencil Sketch App</h2>
</div>
</body>
"""
st.markdown(html_temp, unsafe_allow_html=True)
st.write("-----------------------------------------------------------------------")
st.write("""
st.markdown(html_temp, unsafe_allow_html=True)
st.write("-----------------------------------------------------------------------")
st.write("""
Comment on lines -28 to +38

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

This removes the following comments ( why? ):

#st.error("Select the image to proceed!")

## Packages:
- Streamlit, Opencv, Pillow & numpy
- How to install?
Expand All @@ -45,70 +44,61 @@ def main():
> 3. **pip install numpy**
> 4. **pip install Pillow**
""")
st.write("-----------------------------------------------------------------------")
st.write("-----------------------------------------------------------------------")

# To avoid the deprecation warning while using the file uploader
st.set_option('deprecation.showfileUploaderEncoding', False)
# To avoid the deprecation warning while using the file uploader
st.set_option('deprecation.showfileUploaderEncoding', False)

# Selection box
image_option = st.sidebar.selectbox(
'Image Option',
('None','Sidebar', 'Mainpage')
)
# Selection box
image_option = st.sidebar.selectbox(
'Image Option',
('None','Sidebar', 'Mainpage')
)

# Side bar Selection
if image_option == 'Sidebar':
input_sidebar_image = st.sidebar.file_uploader("Select an image file", type=['jpeg','jpg','png'])
if input_sidebar_image is None:
pass
#st.error("Select the image to proceed!")
else:
st.write("**Side bar Image selected is **")
st.image(input_sidebar_image,use_column_width=True)
input_img = Image.open(input_sidebar_image)
skecthImage = imageConversion(np.array(input_img))
st.write("**Skecthed Image is **")
st.image(skecthImage,use_column_width=True)
# Side bar Selection
if image_option == 'Sidebar':
input_sidebar_image = st.sidebar.file_uploader("Select an image file", type=['jpeg','jpg','png'])
if input_sidebar_image is not None:
st.write("**Side bar Image selected is **")
st.image(input_sidebar_image,use_column_width=True)
input_img = Image.open(input_sidebar_image)
skecthImage = imageConversion(np.array(input_img))
st.write("**Skecthed Image is **")
st.image(skecthImage,use_column_width=True)

elif image_option == 'Mainpage':
input_image = st.file_uploader("Select an image file to process", type=['jpeg','jpg','png'])
if input_image is None:
pass
#st.error("Select the image to proceed!")
else:
st.write("**Main page Image selected is **")
st.image(input_image,use_column_width=True)
input_img = Image.open(input_image)
skecthImage = imageConversion(np.array(input_img))
st.write("**Skecthed Image is **")
st.image(skecthImage,use_column_width=True)
else:
pass

st.sidebar.title("Tip - Run app directly from GitHubLink")
st.sidebar.info(""" streamlit run
elif image_option == 'Mainpage':
input_image = st.file_uploader("Select an image file to process", type=['jpeg','jpg','png'])
if input_image is not None:
st.write("**Main page Image selected is **")
st.image(input_image,use_column_width=True)
input_img = Image.open(input_image)
skecthImage = imageConversion(np.array(input_img))
st.write("**Skecthed Image is **")
st.image(skecthImage,use_column_width=True)
st.sidebar.title("Tip - Run app directly from GitHubLink")
st.sidebar.info(""" streamlit run
https://github.com/SurendraRedd/
StreamlitProjects/blob/master
/sketcher.py
""")
st.sidebar.title("Logic")
st.sidebar.info("""
st.sidebar.title("Logic")
st.sidebar.info("""
- Convert the color image to grayscale - ```gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)```
- Invert the grayscale image to get a negative - ```imagem = cv2.bitwise_not(imagem)```
- Apply a Gaussian blur to the negative from step 2 - ```blur = cv.GaussianBlur()```
- Blend the grayscale image from step 1 with the blurred negative from step 3 using a color dodge - ```dodgeV2(mg_gray, img_blur)```
> [Sketch Reference](https://www.askaswiss.com/2016/01/how-to-create-pencil-sketch-opencv-python.html)
""")
st.sidebar.title("About")
st.sidebar.info("**App version 1.0**")
st.sidebar.title("About")
st.sidebar.info("**App version 1.0**")

if st.checkbox("ShowDemo?"):
st.video(open("Demo.mp4","rb").read())
if st.checkbox("ShowDemo?"):
st.video(open("Demo.mp4","rb").read())

if st.checkbox("Show source code? "):
st.code(open("./sketcher.py", encoding="utf-8").read())
if st.checkbox("Show source code? "):
st.code(open("./sketcher.py", encoding="utf-8").read())

st.info("""
st.info("""
[GitHubLink](https://github.com/SurendraRedd/StreamlitProjects/blob/master/sketcher.py)
""")

Expand Down