seawolf2357 commited on
Commit
79d2b6a
Β·
verified Β·
1 Parent(s): 0f968d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -26
app.py CHANGED
@@ -1,47 +1,106 @@
1
  import streamlit as st
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
 
 
 
 
 
4
 
5
  # 제λͺ©
6
- st.title("Hugging Face와 Streamlit을 μ‚¬μš©ν•œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜")
 
 
 
7
 
8
  # ν…μŠ€νŠΈ μž…λ ₯
9
- user_input = st.text_input("ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”:", "Streamlit은 정말 λ©‹μ Έμš”!")
10
 
11
  # 숫자 μž…λ ₯
12
- number_input = st.number_input("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”:", min_value=0.0, max_value=100.0, value=50.0)
13
 
14
- # μŠ¬λΌμ΄λ”
15
- slider_input = st.slider("μŠ¬λΌμ΄λ”λ‘œ 숫자λ₯Ό μ„ νƒν•˜μ„Έμš”:", 0, 100, 25)
16
 
17
- # 파일 μ—…λ‘œλ”
18
- uploaded_file = st.file_uploader("νŒŒμΌμ„ μ—…λ‘œλ“œν•˜μ„Έμš”:", type=["csv", "txt"])
19
 
20
- # μ²΄ν¬λ°•μŠ€
21
- if st.checkbox("μ²΄ν¬λ°•μŠ€λ₯Ό μ„ νƒν•˜μ„Έμš”:"):
22
- st.write("μ²΄ν¬λ°•μŠ€κ°€ μ„ νƒλ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
23
 
24
- # λΌλ””μ˜€ λ²„νŠΌ
25
- radio_choice = st.radio("λΌλ””μ˜€ λ²„νŠΌμ„ μ„ νƒν•˜μ„Έμš”:", ("μ˜΅μ…˜ 1", "μ˜΅μ…˜ 2", "μ˜΅μ…˜ 3"))
26
- st.write(f"당신은 {radio_choice}을 μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.")
 
 
27
 
28
  # μ…€λ ‰νŠΈλ°•μŠ€
29
- option = st.selectbox("μ…€λ ‰νŠΈλ°•μŠ€μ—μ„œ μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”:", ("μ˜΅μ…˜ A", "μ˜΅μ…˜ B", "μ˜΅μ…˜ C"))
30
- st.write(f"당신은 {option}을 μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.")
31
 
32
  # λ©€ν‹°μ…€λ ‰νŠΈ
33
- options = st.multiselect("λ©€ν‹°μ…€λ ‰νŠΈμ—μ„œ μ—¬λŸ¬ μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”:", ["μ˜΅μ…˜ 1", "μ˜΅μ…˜ 2", "μ˜΅μ…˜ 3", "μ˜΅μ…˜ 4"])
34
- st.write("당신은 ", options, "을 μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.")
 
 
 
 
 
35
 
36
  # λ²„νŠΌ
37
- if st.button("ν΄λ¦­ν•˜μ„Έμš”!"):
38
- st.write("λ²„νŠΌμ΄ ν΄λ¦­λ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
39
-
40
- # 데이터 μ‹œκ°ν™”
41
- st.subheader("κ°„λ‹¨ν•œ 차트:")
42
- # λ¬΄μž‘μœ„ 데이터 생성
43
- data = np.random.randn(100)
44
- # matplotlibλ₯Ό μ‚¬μš©ν•œ 차트
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  fig, ax = plt.subplots()
46
- ax.hist(data, bins=20)
47
  st.pyplot(fig)
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
+ from PIL import Image
6
+ import io
7
+
8
+ # νŽ˜μ΄μ§€ μ„€μ •
9
+ st.set_page_config(page_title="Streamlit UI Components", page_icon=":sparkles:")
10
 
11
  # 제λͺ©
12
+ st.title("Streamlit UI Components μ˜ˆμ‹œ")
13
+
14
+ # λΆ€μ œλͺ©
15
+ st.header("μž…λ ₯ μ»΄ν¬λ„ŒνŠΈ")
16
 
17
  # ν…μŠ€νŠΈ μž…λ ₯
18
+ text_input = st.text_input("ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”")
19
 
20
  # 숫자 μž…λ ₯
21
+ number_input = st.number_input("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”", min_value=0, max_value=100)
22
 
23
+ # ν…μŠ€νŠΈ μ˜μ—­
24
+ text_area = st.text_area("μ—¬λŸ¬ 쀄 ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”")
25
 
26
+ # λ‚ μ§œ μž…λ ₯
27
+ date_input = st.date_input("λ‚ μ§œλ₯Ό μ„ νƒν•˜μ„Έμš”")
28
 
29
+ # μ‹œκ°„ μž…λ ₯
30
+ time_input = st.time_input("μ‹œκ°„μ„ μ„ νƒν•˜μ„Έμš”")
 
31
 
32
+ # 파일 μ—…λ‘œλ“œ
33
+ uploaded_file = st.file_uploader("νŒŒμΌμ„ μ—…λ‘œλ“œν•˜μ„Έμš”", type=["png", "jpg", "jpeg", "txt", "csv"])
34
+
35
+ # μŠ¬λΌμ΄λ”
36
+ slider = st.slider("μŠ¬λΌμ΄λ”λ₯Ό μ‘°μ •ν•˜μ„Έμš”", 0, 100, 50)
37
 
38
  # μ…€λ ‰νŠΈλ°•μŠ€
39
+ selectbox = st.selectbox("μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”", ["μ˜΅μ…˜ 1", "μ˜΅μ…˜ 2", "μ˜΅μ…˜ 3"])
 
40
 
41
  # λ©€ν‹°μ…€λ ‰νŠΈ
42
+ multiselect = st.multiselect("μ—¬λŸ¬ μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”", ["μ˜΅μ…˜ A", "μ˜΅μ…˜ B", "μ˜΅μ…˜ C"])
43
+
44
+ # λΌλ””μ˜€ λ²„νŠΌ
45
+ radio = st.radio("λΌλ””μ˜€ λ²„νŠΌμ—μ„œ μ„ νƒν•˜μ„Έμš”", ["선택 1", "선택 2", "선택 3"])
46
+
47
+ # μ²΄ν¬λ°•μŠ€
48
+ checkbox = st.checkbox("μ²΄ν¬λ°•μŠ€λ₯Ό μ„ νƒν•˜μ„Έμš”")
49
 
50
  # λ²„νŠΌ
51
+ if st.button("ν΄λ¦­ν•˜μ„Έμš”"):
52
+ st.success("λ²„νŠΌμ΄ ν΄λ¦­λ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
53
+
54
+ st.header("좜λ ₯ μ»΄ν¬λ„ŒνŠΈ")
55
+
56
+ # ν…μŠ€νŠΈ 좜λ ₯
57
+ st.write("여기에 ν…μŠ€νŠΈλ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.")
58
+
59
+ # λ°μ΄ν„°ν”„λ ˆμž„ 좜λ ₯
60
+ df = pd.DataFrame({
61
+ 'column 1': [1, 2, 3, 4],
62
+ 'column 2': [10, 20, 30, 40]
63
+ })
64
+ st.dataframe(df)
65
+
66
+ # 차트
67
+ chart_data = pd.DataFrame(np.random.randn(20, 3), columns=['a', 'b', 'c'])
68
+ st.line_chart(chart_data)
69
+
70
+ # κ·Έλ¦Ό 좜λ ₯
71
+ if uploaded_file is not None and uploaded_file.type.startswith("image/"):
72
+ image = Image.open(uploaded_file)
73
+ st.image(image, caption="Uploaded Image")
74
+
75
+ # λΉ„λ””μ˜€ 좜λ ₯
76
+ video_file = open('example.mp4', 'rb')
77
+ video_bytes = video_file.read()
78
+ st.video(video_bytes)
79
+
80
+ # μ½”λ“œ 좜λ ₯
81
+ code = '''def hello():
82
+ print("Hello, Streamlit!")'''
83
+ st.code(code, language='python')
84
+
85
+ # 맡
86
+ map_data = pd.DataFrame({
87
+ 'lat': np.random.randn(10) + 37.76, # μƒŒν”„λž€μ‹œμŠ€μ½” μœ„λ„ μ£Όλ³€
88
+ 'lon': np.random.randn(10) - 122.4 # μƒŒν”„λž€μ‹œμŠ€μ½” 경도 μ£Όλ³€
89
+ })
90
+ st.map(map_data)
91
+
92
+ # 진행바
93
+ import time
94
+ progress_bar = st.progress(0)
95
+ for i in range(100):
96
+ time.sleep(0.1)
97
+ progress_bar.progress(i + 1)
98
+
99
+ st.header("차트 μ˜ˆμ‹œ")
100
+
101
+ # λ§‰λŒ€ 차트
102
  fig, ax = plt.subplots()
103
+ ax.bar(["A", "B", "C"], [10, 20, 15])
104
  st.pyplot(fig)
105
+
106
+ # 주의: μ‹€μ œ μ½”λ“œ 싀행을 μœ„ν•΄μ„œλŠ” 'example.mp4' λΉ„λ””μ˜€ 파일이 ν•„μš”ν•©λ‹ˆλ‹€. ν•΄λ‹Ή 파일이 μ—†λ‹€λ©΄ λΉ„λ””μ˜€ κ΄€λ ¨ μ½”λ“œλ₯Ό 주석 μ²˜λ¦¬ν•˜κ±°λ‚˜ νŒŒμΌμ„ μ€€λΉ„ν•΄μ£Όμ„Έμš”.