Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
grayscale_image = image.convert("L")
|
| 7 |
-
return grayscale_image
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
def
|
| 15 |
-
with gr.Blocks() as
|
| 16 |
-
gr.Markdown("#
|
| 17 |
|
| 18 |
with gr.Row():
|
| 19 |
-
|
| 20 |
-
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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 |
-
|
| 39 |
-
|
|
|
|
| 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()
|