kijeoung commited on
Commit
729e2d3
ยท
verified ยท
1 Parent(s): d815728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -19
app.py CHANGED
@@ -1,25 +1,34 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # ๊ฐ์ • ๋ถ„์„ ๋ชจ๋ธ ๋กœ๋“œ
5
- emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
 
 
6
 
7
- # ์˜ˆ์ธก ํ•จ์ˆ˜
8
- def analyze_emotion(text):
9
- result = emotion_analyzer(text)[0]
10
- label = result['label']
11
- score = result['score'] * 100
12
- return f"{label}, {score:.2f}%"
13
-
14
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
15
- interface = gr.Interface(
16
- fn=analyze_emotion, # ๋ถ„์„ ํ•จ์ˆ˜
17
- inputs=gr.Textbox(lines=2, placeholder="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”..."), # ์ž…๋ ฅ
18
- outputs="text", # ์ถœ๋ ฅ
19
- title="๊ฐ์ • ๋ถ„์„ ์•ฑ",
20
- description="์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ํ…์ŠคํŠธ์˜ ๊ฐ์ •์„ ๋ถ„์„ํ•˜์—ฌ ๋ ˆ์ด๋ธ”๊ณผ ํ™•๋ฅ ๊ฐ’์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค."
21
- )
 
 
 
 
 
 
 
22
 
23
  # ์‹คํ–‰
24
  if __name__ == "__main__":
25
- interface.launch()
 
1
  import gradio as gr
2
+ from PIL import Image
3
 
4
+ def convert_to_grayscale(image):
5
+ # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
6
+ gray_image = image.convert("L")
7
+ return gray_image
8
 
9
+ # Gradio UI ๊ตฌ์„ฑ
10
+ with gr.Blocks() as app:
11
+ gr.Markdown("# ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜")
12
+
13
+ with gr.Row():
14
+ input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€", type="pil")
15
+ output_image = gr.Image(label="ํ‘๋ฐฑ ์ด๋ฏธ์ง€", type="pil")
16
+
17
+ convert_button = gr.Button("๋ณ€ํ™˜ํ•˜๊ธฐ")
18
+ download_button = gr.Button("JPG๋กœ ๋‹ค์šด๋กœ๋“œ")
19
+
20
+ convert_button.click(
21
+ fn=convert_to_grayscale,
22
+ inputs=input_image,
23
+ outputs=output_image
24
+ )
25
+
26
+ download_button.click(
27
+ fn=lambda img: img.save("converted_image.jpg", "JPEG") or "converted_image.jpg",
28
+ inputs=output_image,
29
+ outputs=gr.File(label="JPG ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ")
30
+ )
31
 
32
  # ์‹คํ–‰
33
  if __name__ == "__main__":
34
+ app.launch()