CSB261 commited on
Commit
a0a5234
ยท
verified ยท
1 Parent(s): 1b8e0d0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+
5
+ # OpenAI API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ def call_api(content, system_message, max_tokens=1000, temperature=0.5, top_p=1.0):
9
+ response = openai.ChatCompletion.create(
10
+ model="gpt-4o-mini", # ๋˜๋Š” ๋‹ค๋ฅธ ๋ชจ๋ธ ID ์‚ฌ์šฉ
11
+ messages=[
12
+ {"role": "system", "content": system_message},
13
+ {"role": "user", "content": content},
14
+ ],
15
+ max_tokens=max_tokens,
16
+ temperature=temperature,
17
+ top_p=top_p,
18
+ )
19
+ return response.choices[0].message['content']
20
+
21
+ def translate_code(english_code):
22
+ system_message = "You are a helpful assistant that translates code comments and documentation from English to Korean."
23
+ user_content = f"Please translate the following code from English to Korean:\n\n{english_code}"
24
+ korean_translation = call_api(user_content, system_message)
25
+ return korean_translation
26
+
27
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
28
+ iface = gr.Interface(
29
+ fn=translate_code,
30
+ inputs=gr.inputs.Textbox(lines=20, placeholder="๋ฒˆ์—ญํ•  ์˜์–ด ์ฝ”๋“œ๋ฅผ ์—ฌ๊ธฐ์— ์ž…๋ ฅํ•˜์„ธ์š”."),
31
+ outputs=gr.outputs.Textbox(),
32
+ title="์ฝ”๋“œ ์˜์–ด-ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ๊ธฐ",
33
+ description="์˜์–ด๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•ฉ๋‹ˆ๋‹ค. ๋ฒˆ์—ญํ•  ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๋ฒˆ์—ญ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”."
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ iface.launch()