Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from PIL import Image
|
|
10 |
import io
|
11 |
import gradio as gr
|
12 |
import threading
|
|
|
13 |
|
14 |
# 로깅 설정
|
15 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
@@ -24,6 +25,7 @@ intents.guild_messages = True
|
|
24 |
# PaliGemma 모델 설정 (CPU 모드)
|
25 |
model = PaliGemmaForConditionalGeneration.from_pretrained("gokaygokay/sd3-long-captioner").to("cpu").eval()
|
26 |
processor = PaliGemmaProcessor.from_pretrained("gokaygokay/sd3-long-captioner")
|
|
|
27 |
|
28 |
def modify_caption(caption: str) -> str:
|
29 |
prefix_substrings = [
|
@@ -56,9 +58,16 @@ async def create_captions_rich(image: Image.Image) -> str:
|
|
56 |
modified_caption = modify_caption(decoded)
|
57 |
return modified_caption
|
58 |
|
|
|
|
|
|
|
|
|
|
|
59 |
# Gradio 인터페이스 설정
|
60 |
def create_captions_rich_sync(image):
|
61 |
-
|
|
|
|
|
62 |
|
63 |
css = """
|
64 |
#mkd {
|
@@ -125,7 +134,8 @@ class MyClient(discord.Client):
|
|
125 |
async def process_image(image_url, message):
|
126 |
image = await download_image(image_url)
|
127 |
caption = await create_captions_rich(image)
|
128 |
-
|
|
|
129 |
|
130 |
async def download_image(url):
|
131 |
response = requests.get(url)
|
|
|
10 |
import io
|
11 |
import gradio as gr
|
12 |
import threading
|
13 |
+
from googletrans import Translator
|
14 |
|
15 |
# 로깅 설정
|
16 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
|
|
25 |
# PaliGemma 모델 설정 (CPU 모드)
|
26 |
model = PaliGemmaForConditionalGeneration.from_pretrained("gokaygokay/sd3-long-captioner").to("cpu").eval()
|
27 |
processor = PaliGemmaProcessor.from_pretrained("gokaygokay/sd3-long-captioner")
|
28 |
+
translator = Translator()
|
29 |
|
30 |
def modify_caption(caption: str) -> str:
|
31 |
prefix_substrings = [
|
|
|
58 |
modified_caption = modify_caption(decoded)
|
59 |
return modified_caption
|
60 |
|
61 |
+
async def translate_to_korean(text: str) -> str:
|
62 |
+
loop = asyncio.get_event_loop()
|
63 |
+
translated = await loop.run_in_executor(None, lambda: translator.translate(text, dest='ko').text)
|
64 |
+
return translated
|
65 |
+
|
66 |
# Gradio 인터페이스 설정
|
67 |
def create_captions_rich_sync(image):
|
68 |
+
caption = asyncio.run(create_captions_rich(image))
|
69 |
+
translated_caption = asyncio.run(translate_to_korean(caption))
|
70 |
+
return translated_caption
|
71 |
|
72 |
css = """
|
73 |
#mkd {
|
|
|
134 |
async def process_image(image_url, message):
|
135 |
image = await download_image(image_url)
|
136 |
caption = await create_captions_rich(image)
|
137 |
+
translated_caption = await translate_to_korean(caption)
|
138 |
+
return f"{message.author.mention}, 인식된 이미지 설명: {translated_caption}"
|
139 |
|
140 |
async def download_image(url):
|
141 |
response = requests.get(url)
|