Spaces:
Running
Running
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| # ๐จ ์๊ธฐ์๊ธฐํ๊ณ ํธ๋ ๋ํ ํ ๋ง ์ค์ | |
| theme = gr.themes.Soft(primary_hue="indigo", secondary_hue="blue") | |
| # โญ ์๋ฌ ์์ด ๊ฐ์ฅ ๋๋ํ๊ณ ๋น ๋ฅธ Qwen 2.5 Instruct ๋ชจ๋ธ ์ฌ์ฉ | |
| hf_token = os.environ.get("HF_TOKEN") | |
| client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=hf_token) | |
| def transform_english(basic_text): | |
| if not basic_text: | |
| return "โ ๏ธ ์์ํ ๋ฌธ์ฅ์ ์ ๋ ฅํด์ฃผ์ธ์.", "", "" | |
| if not hf_token: | |
| return "โ HF_TOKEN ์ค์ ์ค๋ฅ", "ํ ํฐ์ ํ์ธํด์ฃผ์ธ์.", "ํ ํฐ์ ํ์ธํด์ฃผ์ธ์." | |
| # AI์๊ฒ 3๊ฐ์ง ์ธ๊ฒฉ์ ๋์์ ๋ถ์ฌํ๋ ๊ฐ๋ ฅํ ํ๋กฌํํธ | |
| prompt = f""" | |
| You are an expert English linguist. Rewrite the following basic English text into three totally different styles. | |
| Basic Text: "{basic_text}" | |
| Task: | |
| 1. [Gen Z / TikTok]: Rewrite it using trendy internet slang, Gen-Z vocabulary, emojis, and a highly dramatic, casual tone. | |
| 2. [Harvard / Business]: Rewrite it in a highly sophisticated, formal, and elegant academic/business tone (like Harvard Business Review). | |
| 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. | |
| Format your response EXACTLY like this with no other text: | |
| [TikTok] | |
| (your text here) | |
| [Harvard] | |
| (your text here) | |
| [CSAT] | |
| (your text here) | |
| """ | |
| try: | |
| response = client.chat_completion( | |
| messages=[{"role": "user", "content": prompt}], | |
| max_tokens=800, | |
| temperature=0.8 # ์ด์ง ์ฐฝ์๋ ฅ์ ๋์ฌ์ ๋ ๊ทน์ ์ธ ๋ณํ๋ฅผ ์ ๋ | |
| ) | |
| result = response.choices[0].message.content | |
| # AI์ ์๋ต์ 3๊ฐ์ ๊ตฌ์ญ์ผ๋ก ์์๊ฒ ์ชผ๊ฐ๊ธฐ | |
| try: | |
| tiktok = result.split("[TikTok]")[1].split("[Harvard]")[0].strip() | |
| harvard = result.split("[Harvard]")[1].split("[CSAT]")[0].strip() | |
| csat = result.split("[CSAT]")[1].strip() | |
| except Exception: | |
| # AI๊ฐ ๊ฐ๋ ์์์ ์ ์งํฌ ๋๋ฅผ ๋๋นํ ์์ธ ์ฒ๋ฆฌ | |
| return result, "๊ฒฐ๊ณผ ํ์ฑ ์๋ฌ", "๊ฒฐ๊ณผ ํ์ฑ ์๋ฌ" | |
| return tiktok, harvard, csat | |
| except Exception as e: | |
| return f"โ ์ค๋ฅ ๋ฐ์: {str(e)}", "", "" | |
| # UI ์ธํฐํ์ด์ค ๊ตฌ์ฑ | |
| with gr.Blocks(theme=theme) as demo: | |
| gr.Markdown("# ๐ญ ์ด๋ฉ ์์์ ํ๋ฒ๋์์ผ๋ก! ๋ค์ค์ธ๊ฒฉ ๊ต์ ๊ธฐ") | |
| gr.Markdown("### ์ฝฉ๊ธ๋ฆฌ์๋ ์์ฃผ ๋จ์ํ ๋ฌธ์ฅ์ ์ ๋ ฅํ๋ฉด, AI๊ฐ 3๊ฐ์ง ์ธ๊ฒฉ์ผ๋ก ์๋ฒฝํ๊ฒ ํฌ์ฅํด๋๋ฆฝ๋๋ค.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### โ๏ธ 1. ๋์ ๊ธฐ์ด ์์ ์ ๋ ฅ") | |
| user_input = gr.Textbox( | |
| label="์์ฃผ ๋จ์ํ ์์ด๋ก ์ ์ด๋ณด์ธ์", | |
| placeholder="์: I go to PC room and play game. It was fun.", | |
| lines=5 | |
| ) | |
| gr.Examples( | |
| examples=[ | |
| "I go to PC room and play game. It was fun.", | |
| "I ate a very big hamburger. My stomach is full.", | |
| "I sleep during math class because the teacher is boring." | |
| ], | |
| inputs=user_input, | |
| label="๐ ๊ฟ์ผ ์ฝฉ๊ธ๋ฆฌ์ ์์ (ํด๋ฆญ!)" | |
| ) | |
| run_btn = gr.Button("โจ ๋ค์ค์ธ๊ฒฉ ๋ณํ ์์! โจ", variant="primary") | |
| with gr.Column(scale=2): | |
| gr.Markdown("### ๐ช 2. AI์ 3๋จ ๋ณ์ ๊ฒฐ๊ณผ") | |
| with gr.Row(): | |
| out_tiktok = gr.Textbox(label="๐ฑ ์์ด๋ฏผ 10๋ ์ฌ๋ญ (ํฑํก/์ธ์คํ ๊ฐ์ฑ)", lines=6, interactive=False) | |
| out_harvard = gr.Textbox(label="๐ ๋น์ฆ๋์ค / ํ๋ฒ๋ (๊ณ ๊ธ ํ์ ํค)", lines=6, interactive=False) | |
| out_csat = gr.Textbox(label="๐ ์๋ฅ 29๋ฒ ์ด๋ฒ (๋ณต์กํ ๋์น/๋ถ์ฌ๊ตฌ๋ฌธ)", lines=6, interactive=False) | |
| run_btn.click( | |
| transform_english, | |
| inputs=[user_input], | |
| outputs=[out_tiktok, out_harvard, out_csat] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |