File size: 3,118 Bytes
4fd3e67
d0a7e74
460508b
 
 
d0a7e74
460508b
 
 
 
 
d0a7e74
460508b
 
d0a7e74
460508b
 
 
 
 
 
 
 
 
 
 
 
d0a7e74
460508b
 
 
 
 
 
 
 
 
 
 
4fd3e67
460508b
 
 
d0a7e74
460508b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0a7e74
460508b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20308f4
 
460508b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr
from transformers import pipeline
import random
from PIL import Image, ImageDraw, ImageFont
import io

# λͺ¨λΈ μ΄ˆκΈ°ν™”
try:
    qa_pipeline = pipeline("question-answering")
except:
    qa_pipeline = None

def create_meme(template_choice, top_text, bottom_text):
    """밈 이미지 생성"""
    try:
        # κ°„λ‹¨ν•œ 밈 이미지 생성
        width, height = 500, 400
        img = Image.new('RGB', (width, height), color='lightblue')
        draw = ImageDraw.Draw(img)
        
        # ν…μŠ€νŠΈ μΆ”κ°€
        if top_text:
            draw.text((50, 50), top_text, fill='black')
        if bottom_text:
            draw.text((50, 350), bottom_text, fill='black')
            
        return img
    except Exception as e:
        return f"였λ₯˜: {str(e)}"

def chatbot_response(message, history):
    """챗봇 응닡"""
    responses = [
        "ν₯미둜운 μ§ˆλ¬Έμ΄λ„€μš”!",
        "더 μžμ„Ένžˆ λ§μ”€ν•΄μ£Όμ„Έμš”.",
        "그것에 λŒ€ν•΄ μƒκ°ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.",
        "쒋은 μ•„μ΄λ””μ–΄μž…λ‹ˆλ‹€!"
    ]
    return random.choice(responses)

# Gradio μΈν„°νŽ˜μ΄μŠ€
with gr.Blocks(title="밈 생성 & 챗봇") as demo:
    gr.Markdown("# 🎭 밈 생성 & AI 챗봇 μ„œλΉ„μŠ€")
    
    with gr.Tabs():
        # 밈 생성 νƒ­
        with gr.TabItem("πŸ–ΌοΈ 밈 생성기"):
            with gr.Row():
                with gr.Column():
                    template_dropdown = gr.Dropdown(
                        choices=["λ“œλ ˆμ΄ν¬ 밈", "λ””μŠ€νŠΈλž™ν‹°λ“œ λ³΄μ΄ν”„λ Œλ“œ", "원 λ‘μŠ€ λ‚« μ‹¬ν”Œλ¦¬"],
                        label="밈 ν…œν”Œλ¦Ώ 선택",
                        value="λ“œλ ˆμ΄ν¬ 밈"
                    )
                    top_text = gr.Textbox(label="상단 ν…μŠ€νŠΈ", value="When you see a bug")
                    bottom_text = gr.Textbox(label="ν•˜λ‹¨ ν…μŠ€νŠΈ", value="But it works in production")
                    create_btn = gr.Button("밈 μƒμ„±ν•˜κΈ°", variant="primary")
                
                with gr.Column():
                    meme_output = gr.Image(label="μƒμ„±λœ 밈")
            
            create_btn.click(create_meme, [template_dropdown, top_text, bottom_text], meme_output)
        
        # 챗봇 νƒ­
        with gr.TabItem("πŸ€– AI 챗봇"):
            chatbot = gr.Chatbot(label="AI μ–΄μ‹œμŠ€ν„΄νŠΈ", height=400)
            msg = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯", placeholder="κΆκΈˆν•œ 것을 λ¬Όμ–΄λ³΄μ„Έμš”...")
            
            def user_msg(message, history):
                return "", history + [[message, None]]
            
            def bot_msg(history):
                if history and history[-1][1] is None:
                    user_message = history[-1][0]
                    bot_response = chatbot_response(user_message, history)
                    history[-1][1] = bot_response
                return history
            
            msg.submit(user_msg, [msg, chatbot], [msg, chatbot]).then(bot_msg, chatbot, chatbot)

if __name__ == "__main__":
    demo.launch()