Download app.py from Ping9gu/my-diary: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/Ping9gu/my-diary/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ping9gu/my-diary/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ping9gu/my-diary/resolve/main/app.py
2.46 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| def generate_diary(keywords): | |
| try: | |
| if not keywords: | |
| return "ν€μλλ₯Ό μ λ ₯ν΄μ£ΌμΈμ." | |
| client = InferenceClient( | |
| model="EleutherAI/polyglot-ko-1.3b", | |
| token=os.environ.get("HUGGINGFACE_API_KEY") | |
| ) | |
| prompt = f"""λ€μμ μ€λ μμλ μΌμ μμ½μ λλ€. μ΄κ²μ λ°νμΌλ‘ μμνκ³ κ°λμ μΈ μΌκΈ°λ₯Ό μμ±ν΄μ£ΌμΈμ. | |
| [μμΈ μꡬμ¬ν] | |
| 1. λμ λΆ: | |
| - κ·Έλ μ λ μ¨λ λΆμκΈ°λ‘ μμ | |
| - μν©κ³Ό λ±μ₯μΈλ¬Ό μκ° | |
| 2. μ κ°: | |
| - ꡬ체μ μΈ λνμ νλ λ¬μ¬ | |
| - μ€κ°μ μ¬μ©ν μ₯λ©΄ λ¬μ¬ | |
| - λ±μ₯μΈλ¬Όλ€μ νμ κ³Ό κ°μ λ³ν | |
| 3. κ°μ κ³Ό μκ°: | |
| - λ΄λ©΄μ κ°μ μ μ¬μΈνκ² νν | |
| - μ¬κ±΄μ λν λμ μκ°κ³Ό κΉ¨λ¬μ | |
| - λ€λ₯Έ μ¬λλ€μ κ°μ μ λν κ³΅κ° | |
| μμ½: | |
| {keywords} | |
| === | |
| μ€λμ μΌκΈ°: | |
| μ€λμ """ | |
| # λ λ¨μν νλΌλ―Έν°λ‘ μλ | |
| response = client.text_generation( | |
| prompt, | |
| max_new_tokens=768, | |
| temperature=0.88, | |
| do_sample=True | |
| ) | |
| if not response: | |
| return "μΌκΈ° μμ±μ μ€ν¨νμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ." | |
| diary_content = response.split("μ€λμ ")[-1].strip() | |
| return "μ€λμ " + diary_content | |
| except Exception as e: | |
| print(f"Error: {str(e)}") | |
| return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}" | |
| # Gradio μΈν°νμ΄μ€ μμ± | |
| demo = gr.Interface( | |
| fn=generate_diary, | |
| inputs=gr.Textbox( | |
| label="μ€λμ ν€μλλ₯Ό μ λ ₯νμΈμ", | |
| placeholder="μ: μ€λ μΉκ΅¬μ μΉ΄νμμ λ§λμ μ¦κ±°μ΄ μκ°μ 보λμ΄μ." | |
| ), | |
| outputs=gr.Textbox(label="μμ±λ μΌκΈ°"), | |
| title="AI μΌκΈ° λμ°λ―Έ π", | |
| description="ν€μλλ₯Ό μ λ ₯νλ©΄ AIκ° κ°μ±μ μΈ μΌκΈ°λ₯Ό μμ±ν΄μ€λλ€.", | |
| examples=[ | |
| ["μ€λ μΉκ΅¬μ μΉ΄νμμ λ§λ λ§μλ μΌμ΄ν¬λ₯Ό λ¨Ήμμ΄"], | |
| ["μ€λμ λΉκ° μμ μ§μμ μ± μ μ½μμ΄"] | |
| ] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |