From 0369c8f1b0597f5df48920520ce3c8a5e9a04de9 Mon Sep 17 00:00:00 2001
From: Sourcery AI <>
Date: Tue, 31 Oct 2023 16:38:05 +0000
Subject: [PATCH] 'Refactored by Sourcery'
---
IrisPrediction.py | 3 +-
StreamlitApps.py | 3 +-
app.py | 18 ++++-----
sketcher.py | 100 +++++++++++++++++++++-------------------------
4 files changed, 56 insertions(+), 68 deletions(-)
diff --git a/IrisPrediction.py b/IrisPrediction.py
index 9375b35..a2a4a79 100644
--- a/IrisPrediction.py
+++ b/IrisPrediction.py
@@ -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])
def main():
st.markdown(html_temp, unsafe_allow_html=True)
diff --git a/StreamlitApps.py b/StreamlitApps.py
index 42d35be..afb87ef 100644
--- a/StreamlitApps.py
+++ b/StreamlitApps.py
@@ -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)
st.title("PencilSketcher App")
diff --git a/app.py b/app.py
index 5e55f2d..17cd18e 100644
--- a/app.py
+++ b/app.py
@@ -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"
+ )
# In[ ]:
@@ -75,7 +76,7 @@ def main():
"""
st.markdown(html_temp,unsafe_allow_html=True)
- st.markdown('{}'.format("people"), unsafe_allow_html=True)
+ st.markdown('people', unsafe_allow_html=True)
st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.latex(r'''
... a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} =
@@ -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')
@@ -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')")
@@ -163,7 +163,7 @@ def main():
["SamaraSimhaReddy", "Simha",
"NarasimhaNaidu", "Legend"])
-
+
# Will only run once if already cached
df = load_data()
st.write(df)
@@ -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
@@ -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!')
diff --git a/sketcher.py b/sketcher.py
index 301d475..5d1956e 100644
--- a/sketcher.py
+++ b/sketcher.py
@@ -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)
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 = """
Image to Pencil Sketch App
"""
- st.markdown(html_temp, unsafe_allow_html=True)
- st.write("-----------------------------------------------------------------------")
- st.write("""
+ st.markdown(html_temp, unsafe_allow_html=True)
+ st.write("-----------------------------------------------------------------------")
+ st.write("""
## Packages:
- Streamlit, Opencv, Pillow & numpy
- How to install?
@@ -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)
""")