kijeoung commited on
Commit
249a64a
ยท
verified ยท
1 Parent(s): e5df068

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -30
app.py CHANGED
@@ -1,39 +1,48 @@
1
  import gradio as gr
2
- from PIL import Image
 
3
 
4
- def convert_to_grayscale(image):
5
- # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
6
- grayscale_image = image.convert("L")
7
- return grayscale_image
8
 
9
- def blend_images(original, grayscale, blend):
10
- # ์›๋ณธ๊ณผ ํ‘๋ฐฑ ์ด๋ฏธ์ง€ ์‚ฌ์ด์˜ ๋ธ”๋ Œ๋“œ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜
11
- return Image.blend(original, grayscale, blend)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # ๊ทธ๋ผ๋””์˜ค ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
14
- def create_interface():
15
- with gr.Blocks() as demo:
16
- gr.Markdown("# ํ‘๋ฐฑ ์‚ฌ์ง„ ๋ณ€ํ™˜๊ธฐ\n์ผ๋ฐ˜ ์‚ฌ์ง„์„ ํ‘๋ฐฑ ์‚ฌ์ง„์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์Šฌ๋ผ์ด๋“œ๋ฐ”๋ฅผ ํ†ตํ•ด ์›๋ณธ๊ณผ ๋น„๊ตํ•ด๋ณด์„ธ์š”.")
17
 
18
  with gr.Row():
19
- with gr.Column():
20
- image_input = gr.Image(type="pil", label="์›๋ณธ ์ด๋ฏธ์ง€ ์ž…๋ ฅ")
21
- blend_slider = gr.Slider(0, 1, value=0.5, label="์Šฌ๋ผ์ด๋“œ๋ฐ” (0: ์›๋ณธ, 1: ํ‘๋ฐฑ)")
22
-
23
- with gr.Column():
24
- image_output = gr.Image(type="pil", label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง€ ์ถœ๋ ฅ")
25
 
26
- def update_output(image, blend):
27
- grayscale = convert_to_grayscale(image)
28
- blended_image = blend_images(image, grayscale, blend)
29
- return blended_image
30
-
31
- image_input.change(fn=update_output, inputs=[image_input, blend_slider], outputs=image_output)
32
- blend_slider.change(fn=update_output, inputs=[image_input, blend_slider], outputs=image_output)
33
-
34
- return demo
35
 
36
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
37
  if __name__ == "__main__":
38
- demo = create_interface()
39
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
+ import openai
4
 
5
+ # OpenAI API ํ‚ค ์„ค์ •
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
7
 
8
+ def translate_code_to_korean(code):
9
+ """
10
+ ์˜์–ด ์ฝ”๋“œ๋ฅผ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•˜๋Š” ํ•จ์ˆ˜
11
+ """
12
+ system_message = (
13
+ "You are an AI language model specializing in translating programming-related texts from English to Korean. "
14
+ "Ensure that the translations are accurate and preserve technical meaning."
15
+ )
16
+ try:
17
+ # OpenAI API ํ˜ธ์ถœ
18
+ response = openai.ChatCompletion.create(
19
+ model="gpt-4o-mini",
20
+ messages=[
21
+ {"role": "system", "content": system_message},
22
+ {"role": "user", "content": code},
23
+ ],
24
+ max_tokens=1500,
25
+ temperature=0.7,
26
+ top_p=0.9,
27
+ )
28
+ return response.choices[0].message['content']
29
+ except Exception as e:
30
+ return f"์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
31
 
32
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
33
+ def interface():
34
+ with gr.Blocks() as app:
35
+ gr.Markdown("# ์ฝ”๋“œ ์˜์–ด-ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ๊ธฐ\n์˜์–ด๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญ๋ฉ๋‹ˆ๋‹ค.")
36
 
37
  with gr.Row():
38
+ input_code = gr.Textbox(label="์˜์–ด ์ฝ”๋“œ ์ž…๋ ฅ", lines=10, placeholder="์—ฌ๊ธฐ์— ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
39
+ output_translation = gr.Textbox(label="ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ ๊ฒฐ๊ณผ", lines=10, interactive=False)
 
 
 
 
40
 
41
+ translate_button = gr.Button("๋ฒˆ์—ญ ์‹คํ–‰")
42
+ translate_button.click(translate_code_to_korean, inputs=[input_code], outputs=[output_translation])
43
+
44
+ return app
 
 
 
 
 
45
 
 
46
  if __name__ == "__main__":
47
+ app = interface()
48
+ app.launch()