Spaces:
Running
Running
Create app.py
Browse files
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()
|