Upload 4 files
Browse files
app.py
CHANGED
|
@@ -1,56 +1,82 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# ๋ชจ๋ธ
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def
|
|
|
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
-
return f"์ค๋ฅ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
# Gradio ์ธํฐํ์ด์ค
|
| 20 |
-
with gr.Blocks() as demo:
|
| 21 |
-
gr.Markdown("#
|
| 22 |
|
| 23 |
-
with gr.
|
| 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 |
-
# ์ค์: Spaces ๋ฐฐํฌ์ ์ด ๋ถ๋ถ์ด ํต์ฌ
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
demo.launch(
|
| 53 |
-
server_name="0.0.0.0", # ๋ชจ๋ IP์์ ์ ๊ทผ ๊ฐ๋ฅ
|
| 54 |
-
server_port=7860, # ๊ธฐ๋ณธ ํฌํธ
|
| 55 |
-
share=False # Spaces์์๋ False ์ฌ์ฉ
|
| 56 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import random
|
| 4 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
+
# ๋ชจ๋ธ ์ด๊ธฐํ
|
| 8 |
+
try:
|
| 9 |
+
qa_pipeline = pipeline("question-answering")
|
| 10 |
+
except:
|
| 11 |
+
qa_pipeline = None
|
| 12 |
|
| 13 |
+
def create_meme(template_choice, top_text, bottom_text):
|
| 14 |
+
"""๋ฐ ์ด๋ฏธ์ง ์์ฑ"""
|
| 15 |
try:
|
| 16 |
+
# ๊ฐ๋จํ ๋ฐ ์ด๋ฏธ์ง ์์ฑ
|
| 17 |
+
width, height = 500, 400
|
| 18 |
+
img = Image.new('RGB', (width, height), color='lightblue')
|
| 19 |
+
draw = ImageDraw.Draw(img)
|
| 20 |
+
|
| 21 |
+
# ํ
์คํธ ์ถ๊ฐ
|
| 22 |
+
if top_text:
|
| 23 |
+
draw.text((50, 50), top_text, fill='black')
|
| 24 |
+
if bottom_text:
|
| 25 |
+
draw.text((50, 350), bottom_text, fill='black')
|
| 26 |
+
|
| 27 |
+
return img
|
| 28 |
except Exception as e:
|
| 29 |
+
return f"์ค๋ฅ: {str(e)}"
|
| 30 |
+
|
| 31 |
+
def chatbot_response(message, history):
|
| 32 |
+
"""์ฑ๋ด ์๋ต"""
|
| 33 |
+
responses = [
|
| 34 |
+
"ํฅ๋ฏธ๋ก์ด ์ง๋ฌธ์ด๋ค์!",
|
| 35 |
+
"๋ ์์ธํ ๋ง์ํด์ฃผ์ธ์.",
|
| 36 |
+
"๊ทธ๊ฒ์ ๋ํด ์๊ฐํด๋ณด๊ฒ ์ต๋๋ค.",
|
| 37 |
+
"์ข์ ์์ด๋์ด์
๋๋ค!"
|
| 38 |
+
]
|
| 39 |
+
return random.choice(responses)
|
| 40 |
|
| 41 |
+
# Gradio ์ธํฐํ์ด์ค
|
| 42 |
+
with gr.Blocks(title="๋ฐ ์์ฑ & ์ฑ๋ด") as demo:
|
| 43 |
+
gr.Markdown("# ๐ญ ๋ฐ ์์ฑ & AI ์ฑ๋ด ์๋น์ค")
|
| 44 |
|
| 45 |
+
with gr.Tabs():
|
| 46 |
+
# ๋ฐ ์์ฑ ํญ
|
| 47 |
+
with gr.TabItem("๐ผ๏ธ ๋ฐ ์์ฑ๊ธฐ"):
|
| 48 |
+
with gr.Row():
|
| 49 |
+
with gr.Column():
|
| 50 |
+
template_dropdown = gr.Dropdown(
|
| 51 |
+
choices=["๋๋ ์ดํฌ ๋ฐ", "๋์คํธ๋ํฐ๋ ๋ณด์ดํ๋ ๋", "์ ๋์ค ๋ซ ์ฌํ๋ฆฌ"],
|
| 52 |
+
label="๋ฐ ํ
ํ๋ฆฟ ์ ํ",
|
| 53 |
+
value="๋๋ ์ดํฌ ๋ฐ"
|
| 54 |
+
)
|
| 55 |
+
top_text = gr.Textbox(label="์๋จ ํ
์คํธ", value="When you see a bug")
|
| 56 |
+
bottom_text = gr.Textbox(label="ํ๋จ ํ
์คํธ", value="But it works in production")
|
| 57 |
+
create_btn = gr.Button("๋ฐ ์์ฑํ๊ธฐ", variant="primary")
|
| 58 |
+
|
| 59 |
+
with gr.Column():
|
| 60 |
+
meme_output = gr.Image(label="์์ฑ๋ ๋ฐ")
|
| 61 |
+
|
| 62 |
+
create_btn.click(create_meme, [template_dropdown, top_text, bottom_text], meme_output)
|
| 63 |
|
| 64 |
+
# ์ฑ๋ด ํญ
|
| 65 |
+
with gr.TabItem("๐ค AI ์ฑ๋ด"):
|
| 66 |
+
chatbot = gr.Chatbot(label="AI ์ด์์คํดํธ", height=400)
|
| 67 |
+
msg = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="๊ถ๊ธํ ๊ฒ์ ๋ฌผ์ด๋ณด์ธ์...")
|
| 68 |
+
|
| 69 |
+
def user_msg(message, history):
|
| 70 |
+
return "", history + [[message, None]]
|
| 71 |
+
|
| 72 |
+
def bot_msg(history):
|
| 73 |
+
if history and history[-1][1] is None:
|
| 74 |
+
user_message = history[-1][0]
|
| 75 |
+
bot_response = chatbot_response(user_message, history)
|
| 76 |
+
history[-1][1] = bot_response
|
| 77 |
+
return history
|
| 78 |
+
|
| 79 |
+
msg.submit(user_msg, [msg, chatbot], [msg, chatbot]).then(bot_msg, chatbot, chatbot)
|
| 80 |
|
|
|
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|