minju0730 commited on
Commit
2130fa4
ยท
verified ยท
1 Parent(s): 75f4936

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -5,6 +5,36 @@ import pandas_bokeh
5
  import folium
6
  from streamlit_folium import st_folium
7
  import requests
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  st.markdown('# ๋Š˜์–ด๋‚˜๋Š” ๋ฌด์ธ ์ ํฌ ์ ˆ๋„ ์—…์ฃผ๋“ค "ํ”ผํ•ด ๋ง‰๋ง‰ํ•ด"')
10
 
 
5
  import folium
6
  from streamlit_folium import st_folium
7
  import requests
8
+ import streamlit as st
9
+ from PIL import Image, ExifTags
10
+
11
+ def correct_image_orientation(image):
12
+ try:
13
+ for orientation in ExifTags.TAGS.keys():
14
+ if ExifTags.TAGS[orientation] == 'Orientation':
15
+ break
16
+ exif = image._getexif()
17
+ if exif is not None:
18
+ if exif[orientation] == 3:
19
+ image = image.rotate(180, expand=True)
20
+ elif exif[orientation] == 6:
21
+ image = image.rotate(270, expand=True)
22
+ elif exif[orientation] == 8:
23
+ image = image.rotate(90, expand=True)
24
+ except (AttributeError, KeyError, IndexError):
25
+ # cases: image don't have getexif
26
+ pass
27
+ return image
28
+
29
+ st.title('Image Upload and Rotate Example')
30
+
31
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
32
+
33
+ if uploaded_file is not None:
34
+ image = Image.open(uploaded_file)
35
+ corrected_image = correct_image_orientation(image)
36
+ st.image(corrected_image, caption='Corrected Image', use_column_width=True)
37
+
38
 
39
  st.markdown('# ๋Š˜์–ด๋‚˜๋Š” ๋ฌด์ธ ์ ํฌ ์ ˆ๋„ ์—…์ฃผ๋“ค "ํ”ผํ•ด ๋ง‰๋ง‰ํ•ด"')
40