englissi commited on
Commit
6d11e07
ยท
verified ยท
1 Parent(s): c38c158

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ # ๐ŸŽจ ์•„๊ธฐ์ž๊ธฐํ•˜๊ณ  ํŠธ๋ Œ๋””ํ•œ ํ…Œ๋งˆ ์„ค์ •
6
+ theme = gr.themes.Soft(primary_hue="indigo", secondary_hue="blue")
7
+
8
+ # โญ ์—๋Ÿฌ ์—†์ด ๊ฐ€์žฅ ๋˜‘๋˜‘ํ•˜๊ณ  ๋น ๋ฅธ Qwen 2.5 Instruct ๋ชจ๋ธ ์‚ฌ์šฉ
9
+ hf_token = os.environ.get("HF_TOKEN")
10
+ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=hf_token)
11
+
12
+ def transform_english(basic_text):
13
+ if not basic_text:
14
+ return "โš ๏ธ ์˜์ž‘ํ•  ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.", "", ""
15
+ if not hf_token:
16
+ return "โŒ HF_TOKEN ์„ค์ • ์˜ค๋ฅ˜", "ํ† ํฐ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.", "ํ† ํฐ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”."
17
+
18
+ # AI์—๊ฒŒ 3๊ฐ€์ง€ ์ธ๊ฒฉ์„ ๋™์‹œ์— ๋ถ€์—ฌํ•˜๋Š” ๊ฐ•๋ ฅํ•œ ํ”„๋กฌํ”„ํŠธ
19
+ prompt = f"""
20
+ You are an expert English linguist. Rewrite the following basic English text into three totally different styles.
21
+
22
+ Basic Text: "{basic_text}"
23
+
24
+ Task:
25
+ 1. [Gen Z / TikTok]: Rewrite it using trendy internet slang, Gen-Z vocabulary, emojis, and a highly dramatic, casual tone.
26
+ 2. [Harvard / Business]: Rewrite it in a highly sophisticated, formal, and elegant academic/business tone (like Harvard Business Review).
27
+ 3. [Korean CSAT (์ˆ˜๋Šฅ)]: Rewrite it using unnecessarily complex grammatical structures typical of the Korean CSAT reading section. Forcefully include inversions (e.g., Not only did...), participial phrases, and heavy abstract vocabulary.
28
+
29
+ Format your response EXACTLY like this with no other text:
30
+ [TikTok]
31
+ (your text here)
32
+ [Harvard]
33
+ (your text here)
34
+ [CSAT]
35
+ (your text here)
36
+ """
37
+
38
+ try:
39
+ response = client.chat_completion(
40
+ messages=[{"role": "user", "content": prompt}],
41
+ max_tokens=800,
42
+ temperature=0.8 # ์‚ด์ง ์ฐฝ์˜๋ ฅ์„ ๋†’์—ฌ์„œ ๋” ๊ทน์ ์ธ ๋ณ€ํ™”๋ฅผ ์œ ๋„
43
+ )
44
+ result = response.choices[0].message.content
45
+
46
+ # AI์˜ ์‘๋‹ต์„ 3๊ฐœ์˜ ๊ตฌ์—ญ์œผ๋กœ ์˜ˆ์˜๊ฒŒ ์ชผ๊ฐœ๊ธฐ
47
+ try:
48
+ tiktok = result.split("[TikTok]")[1].split("[Harvard]")[0].strip()
49
+ harvard = result.split("[Harvard]")[1].split("[CSAT]")[0].strip()
50
+ csat = result.split("[CSAT]")[1].strip()
51
+ except Exception:
52
+ # AI๊ฐ€ ๊ฐ€๋” ์–‘์‹์„ ์•ˆ ์ง€ํ‚ฌ ๋•Œ๋ฅผ ๋Œ€๋น„ํ•œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
53
+ return result, "๊ฒฐ๊ณผ ํŒŒ์‹ฑ ์—๋Ÿฌ", "๊ฒฐ๊ณผ ํŒŒ์‹ฑ ์—๋Ÿฌ"
54
+
55
+ return tiktok, harvard, csat
56
+
57
+ except Exception as e:
58
+ return f"โŒ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", "", ""
59
+
60
+ # UI ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
61
+ with gr.Blocks(theme=theme) as demo:
62
+ gr.Markdown("# ๐ŸŽญ ์ดˆ๋”ฉ ์˜์ž‘์„ ํ•˜๋ฒ„๋“œ์ƒ์œผ๋กœ! ๋‹ค์ค‘์ธ๊ฒฉ ๊ต์ •๊ธฐ")
63
+ gr.Markdown("### ์ฝฉ๊ธ€๋ฆฌ์‹œ๋‚˜ ์•„์ฃผ ๋‹จ์ˆœํ•œ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜๋ฉด, AI๊ฐ€ 3๊ฐ€์ง€ ์ธ๊ฒฉ์œผ๋กœ ์™„๋ฒฝํ•˜๊ฒŒ ํฌ์žฅํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค.")
64
+
65
+ with gr.Row():
66
+ with gr.Column(scale=1):
67
+ gr.Markdown("### โœ๏ธ 1. ๋‚˜์˜ ๊ธฐ์ดˆ ์˜์ž‘ ์ž…๋ ฅ")
68
+ user_input = gr.Textbox(
69
+ label="์•„์ฃผ ๋‹จ์ˆœํ•œ ์˜์–ด๋กœ ์ ์–ด๋ณด์„ธ์š”",
70
+ placeholder="์˜ˆ: I go to PC room and play game. It was fun.",
71
+ lines=5
72
+ )
73
+
74
+ gr.Examples(
75
+ examples=[
76
+ "I go to PC room and play game. It was fun.",
77
+ "I ate a very big hamburger. My stomach is full.",
78
+ "I sleep during math class because the teacher is boring."
79
+ ],
80
+ inputs=user_input,
81
+ label="๐ŸŒŸ ๊ฟ€์žผ ์ฝฉ๊ธ€๋ฆฌ์‹œ ์˜ˆ์‹œ (ํด๋ฆญ!)"
82
+ )
83
+
84
+ run_btn = gr.Button("โœจ ๋‹ค์ค‘์ธ๊ฒฉ ๋ณ€ํ™˜ ์‹œ์ž‘! โœจ", variant="primary")
85
+
86
+ with gr.Column(scale=2):
87
+ gr.Markdown("### ๐Ÿช„ 2. AI์˜ 3๋‹จ ๋ณ€์‹  ๊ฒฐ๊ณผ")
88
+ with gr.Row():
89
+ out_tiktok = gr.Textbox(label="๐Ÿ“ฑ ์›์–ด๋ฏผ 10๋Œ€ ์Šฌ๋žญ (ํ‹ฑํ†ก/์ธ์Šคํƒ€ ๊ฐ์„ฑ)", lines=6, interactive=False)
90
+ out_harvard = gr.Textbox(label="๐Ÿ‘” ๋น„์ฆˆ๋‹ˆ์Šค / ํ•˜๋ฒ„๋“œ (๊ณ ๊ธ‰ ํ•™์ˆ  ํ†ค)", lines=6, interactive=False)
91
+ out_csat = gr.Textbox(label="๐Ÿ˜ˆ ์ˆ˜๋Šฅ 29๋ฒˆ ์–ด๋ฒ• (๋ณต์žกํ•œ ๋„์น˜/๋ถ„์‚ฌ๊ตฌ๋ฌธ)", lines=6, interactive=False)
92
+
93
+ run_btn.click(
94
+ transform_english,
95
+ inputs=[user_input],
96
+ outputs=[out_tiktok, out_harvard, out_csat]
97
+ )
98
+
99
+ if __name__ == "__main__":
100
+ demo.launch()