Spaces:
Sleeping
Sleeping
Auto commit at 07-2025-08 1:02:24
Browse files- app.py +318 -107
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -5,6 +5,10 @@ import json
|
|
| 5 |
import traceback
|
| 6 |
from transformers import AutoTokenizer
|
| 7 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# .env ํ์ผ์์ ํ๊ฒฝ ๋ณ์ ๋ก๋
|
| 10 |
try:
|
|
@@ -48,17 +52,38 @@ try:
|
|
| 48 |
|
| 49 |
print(" ์ปค์คํ
๋ชจ๋ธ ๋ก๋ฉ ์ค...")
|
| 50 |
# ์ปค์คํ
๋ชจ๋ธ ํด๋์ค import (Space ํด๋์ modeling.py ์ฌ์ฉ)
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
torch_dtype
|
| 57 |
-
trust_remote_code
|
| 58 |
-
device_map
|
| 59 |
-
low_cpu_mem_usage
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
else:
|
| 63 |
print(" โ ๏ธ ํ ํฐ์ด ์์ด์ ๊ณต๊ฐ ๋ชจ๋ธ ์ฌ์ฉ")
|
| 64 |
MODEL_NAME = "microsoft/DialoGPT-medium"
|
|
@@ -88,16 +113,84 @@ print(f"\n3. ์ต์ข
์ํ:")
|
|
| 88 |
print(f" MODEL_LOADED: {MODEL_LOADED}")
|
| 89 |
print(f" ์ต์ข
๋ชจ๋ธ๋ช
: {MODEL_NAME}")
|
| 90 |
|
| 91 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if not MODEL_LOADED:
|
|
|
|
| 93 |
return "โ ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์์ต๋๋ค."
|
|
|
|
| 94 |
try:
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
with torch.no_grad():
|
| 98 |
-
if
|
|
|
|
| 99 |
# ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฉํฐ๋ชจ๋ฌ ์์ฑ
|
| 100 |
-
from PIL import Image
|
| 101 |
import torchvision.transforms as transforms
|
| 102 |
|
| 103 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
|
@@ -107,85 +200,157 @@ def chat_with_model(message, history, image=None):
|
|
| 107 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 108 |
])
|
| 109 |
|
| 110 |
-
|
| 111 |
-
pil_image = Image.open(image).convert('RGB')
|
| 112 |
-
else:
|
| 113 |
-
pil_image = image.convert('RGB')
|
| 114 |
-
|
| 115 |
pixel_values = transform(pil_image).unsqueeze(0)
|
| 116 |
image_metas = {"vision_grid_thw": torch.tensor([[1, 14, 14]])} # ๊ธฐ๋ณธ ๊ทธ๋ฆฌ๋ ํฌ๊ธฐ
|
| 117 |
|
|
|
|
|
|
|
|
|
|
| 118 |
# ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ์ forward ๋ฉ์๋ ์ฌ์ฉ
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
else:
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# outputs๊ฐ ํํ์ธ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์์ ์ฌ์ฉ
|
| 141 |
if isinstance(outputs, tuple):
|
|
|
|
| 142 |
logits = outputs[0]
|
|
|
|
| 143 |
else:
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
|
|
|
| 146 |
# ๊ฐ์ฅ ๋์ ํ๋ฅ ์ ํ ํฐ ์ ํ
|
| 147 |
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 148 |
generated_tokens = [next_token]
|
|
|
|
| 149 |
|
| 150 |
# ์ถ๊ฐ ํ ํฐ ์์ฑ
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
inputs["input_ids"] = torch.cat([inputs["input_ids"], next_token.unsqueeze(-1)], dim=-1)
|
| 153 |
inputs["attention_mask"] = torch.cat([inputs["attention_mask"], torch.ones_like(next_token.unsqueeze(-1))], dim=-1)
|
| 154 |
|
| 155 |
with torch.no_grad():
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
|
|
|
| 168 |
# ์์ฑ๋ ํ ํฐ๋ค์ ๋์ฝ๋ฉ
|
| 169 |
generated_ids = torch.cat(generated_tokens, dim=0)
|
| 170 |
response = tokenizer.decode(generated_ids, skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
response = response.replace(message, "").strip()
|
| 174 |
return response if response else "์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ ์ ์์ต๋๋ค."
|
| 175 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 177 |
|
| 178 |
-
def solve_math_problem(problem,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
if not MODEL_LOADED:
|
|
|
|
| 180 |
return "โ ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์์ต๋๋ค."
|
|
|
|
| 181 |
try:
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
|
|
|
| 185 |
with torch.no_grad():
|
| 186 |
-
if
|
|
|
|
| 187 |
# ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฉํฐ๋ชจ๋ฌ ์์ฑ
|
| 188 |
-
from PIL import Image
|
| 189 |
import torchvision.transforms as transforms
|
| 190 |
|
| 191 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
|
@@ -195,72 +360,118 @@ def solve_math_problem(problem, image=None):
|
|
| 195 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 196 |
])
|
| 197 |
|
| 198 |
-
|
| 199 |
-
pil_image = Image.open(image).convert('RGB')
|
| 200 |
-
else:
|
| 201 |
-
pil_image = image.convert('RGB')
|
| 202 |
-
|
| 203 |
pixel_values = transform(pil_image).unsqueeze(0)
|
| 204 |
image_metas = {"vision_grid_thw": torch.tensor([[1, 14, 14]])} # ๊ธฐ๋ณธ ๊ทธ๋ฆฌ๋ ํฌ๊ธฐ
|
| 205 |
|
|
|
|
|
|
|
|
|
|
| 206 |
# ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ์ forward ๋ฉ์๋ ์ฌ์ฉ
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
else:
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
# outputs๊ฐ ํํ์ธ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์์ ์ฌ์ฉ
|
| 229 |
if isinstance(outputs, tuple):
|
|
|
|
| 230 |
logits = outputs[0]
|
|
|
|
| 231 |
else:
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
|
|
|
| 234 |
# ๊ฐ์ฅ ๋์ ํ๋ฅ ์ ํ ํฐ ์ ํ
|
| 235 |
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 236 |
generated_tokens = [next_token]
|
|
|
|
| 237 |
|
| 238 |
# ์ถ๊ฐ ํ ํฐ ์์ฑ
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
inputs["input_ids"] = torch.cat([inputs["input_ids"], next_token.unsqueeze(-1)], dim=-1)
|
| 241 |
inputs["attention_mask"] = torch.cat([inputs["attention_mask"], torch.ones_like(next_token.unsqueeze(-1))], dim=-1)
|
| 242 |
|
| 243 |
with torch.no_grad():
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
|
|
|
| 256 |
# ์์ฑ๋ ํ ํฐ๋ค์ ๋์ฝ๋ฉ
|
| 257 |
generated_ids = torch.cat(generated_tokens, dim=0)
|
| 258 |
response = tokenizer.decode(generated_ids, skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
-
|
| 261 |
-
response = response.replace(prompt, "").strip()
|
| 262 |
return response if response else "์ฃ์กํฉ๋๋ค. ์ํ ๋ฌธ์ ๋ฅผ ํ ์ ์์ต๋๋ค."
|
| 263 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 265 |
|
| 266 |
with gr.Blocks(title="Lily Math RAG System", theme=gr.themes.Soft()) as demo:
|
|
@@ -274,16 +485,16 @@ with gr.Blocks(title="Lily Math RAG System", theme=gr.themes.Soft()) as demo:
|
|
| 274 |
msg = gr.Textbox(label="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์", placeholder="์๋
ํ์ธ์! ์ํ ๋ฌธ์ ๋ฅผ ๋์์ฃผ์ธ์.", lines=2)
|
| 275 |
clear = gr.Button("๋ํ ์ด๊ธฐํ")
|
| 276 |
with gr.Column(scale=1):
|
| 277 |
-
gr.Markdown("###
|
| 278 |
-
|
| 279 |
-
gr.Markdown("
|
| 280 |
|
| 281 |
-
def respond(message, chat_history,
|
| 282 |
-
bot_message = chat_with_model(message, chat_history,
|
| 283 |
chat_history.append({"role": "user", "content": message})
|
| 284 |
chat_history.append({"role": "assistant", "content": bot_message})
|
| 285 |
return "", chat_history
|
| 286 |
-
msg.submit(respond, [msg, chatbot,
|
| 287 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 288 |
|
| 289 |
with gr.Tab("๐งฎ ์ํ ๋ฌธ์ ํด๊ฒฐ"):
|
|
@@ -292,12 +503,12 @@ with gr.Blocks(title="Lily Math RAG System", theme=gr.themes.Soft()) as demo:
|
|
| 292 |
math_input = gr.Textbox(label="์ํ ๋ฌธ์ ", placeholder="์: 2x + 5 = 13", lines=3)
|
| 293 |
solve_btn = gr.Button("๋ฌธ์ ํ๊ธฐ", variant="primary")
|
| 294 |
with gr.Column(scale=1):
|
| 295 |
-
gr.Markdown("###
|
| 296 |
-
|
| 297 |
-
gr.Markdown("์ํ ๋ฌธ์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ๋ ์ ํํ ๋ต๋ณ์ ๋ฐ์ ์ ์์ต๋๋ค.")
|
| 298 |
with gr.Column(scale=2):
|
| 299 |
math_output = gr.Textbox(label="ํด๋ต", lines=8, interactive=False)
|
| 300 |
-
solve_btn.click(solve_math_problem, [math_input,
|
| 301 |
|
| 302 |
with gr.Tab("โ๏ธ ์ค์ "):
|
| 303 |
gr.Markdown("## ์์คํ
์ ๋ณด")
|
|
|
|
| 5 |
import traceback
|
| 6 |
from transformers import AutoTokenizer
|
| 7 |
import torch
|
| 8 |
+
import fitz # PyMuPDF
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import io
|
| 11 |
+
import base64
|
| 12 |
|
| 13 |
# .env ํ์ผ์์ ํ๊ฒฝ ๋ณ์ ๋ก๋
|
| 14 |
try:
|
|
|
|
| 52 |
|
| 53 |
print(" ์ปค์คํ
๋ชจ๋ธ ๋ก๋ฉ ์ค...")
|
| 54 |
# ์ปค์คํ
๋ชจ๋ธ ํด๋์ค import (Space ํด๋์ modeling.py ์ฌ์ฉ)
|
| 55 |
+
try:
|
| 56 |
+
from modeling import KananaVForConditionalGeneration
|
| 57 |
+
print(" โ
modeling.py import ์ฑ๊ณต")
|
| 58 |
+
except Exception as import_error:
|
| 59 |
+
print(f" โ modeling.py import ์คํจ: {import_error}")
|
| 60 |
+
raise import_error
|
| 61 |
|
| 62 |
+
try:
|
| 63 |
+
print(f" ๋ชจ๋ธ ๋ก๋ฉ ํ๋ผ๋ฏธํฐ:")
|
| 64 |
+
print(f" MODEL_NAME: {MODEL_NAME}")
|
| 65 |
+
print(f" torch_dtype: {torch.float16}")
|
| 66 |
+
print(f" trust_remote_code: True")
|
| 67 |
+
print(f" device_map: None")
|
| 68 |
+
print(f" low_cpu_mem_usage: True")
|
| 69 |
+
|
| 70 |
+
model = KananaVForConditionalGeneration.from_pretrained(
|
| 71 |
+
MODEL_NAME,
|
| 72 |
+
token=HF_TOKEN,
|
| 73 |
+
torch_dtype=torch.float16,
|
| 74 |
+
trust_remote_code=True,
|
| 75 |
+
device_map=None,
|
| 76 |
+
low_cpu_mem_usage=True
|
| 77 |
+
)
|
| 78 |
+
print(" โ
์ปค์คํ
๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ")
|
| 79 |
+
print(f" ๋ชจ๋ธ ํ์
: {type(model)}")
|
| 80 |
+
print(f" ๋ชจ๋ธ ๋๋ฐ์ด์ค: {next(model.parameters()).device}")
|
| 81 |
+
except Exception as model_error:
|
| 82 |
+
print(f" โ ์ปค์คํ
๋ชจ๋ธ ๋ก๋ฉ ์คํจ: {model_error}")
|
| 83 |
+
print(f" ์ค๋ฅ ํ์
: {type(model_error).__name__}")
|
| 84 |
+
import traceback
|
| 85 |
+
traceback.print_exc()
|
| 86 |
+
raise model_error
|
| 87 |
else:
|
| 88 |
print(" โ ๏ธ ํ ํฐ์ด ์์ด์ ๊ณต๊ฐ ๋ชจ๋ธ ์ฌ์ฉ")
|
| 89 |
MODEL_NAME = "microsoft/DialoGPT-medium"
|
|
|
|
| 113 |
print(f" MODEL_LOADED: {MODEL_LOADED}")
|
| 114 |
print(f" ์ต์ข
๋ชจ๋ธ๋ช
: {MODEL_NAME}")
|
| 115 |
|
| 116 |
+
def extract_text_from_pdf(pdf_file):
|
| 117 |
+
"""PDF์์ ํ
์คํธ ์ถ์ถ"""
|
| 118 |
+
try:
|
| 119 |
+
doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
|
| 120 |
+
text = ""
|
| 121 |
+
for page in doc:
|
| 122 |
+
text += page.get_text()
|
| 123 |
+
doc.close()
|
| 124 |
+
return text
|
| 125 |
+
except Exception as e:
|
| 126 |
+
return f"PDF ์ฝ๊ธฐ ์ค๋ฅ: {str(e)}"
|
| 127 |
+
|
| 128 |
+
def extract_text_from_image(image_file):
|
| 129 |
+
"""์ด๋ฏธ์ง์์ OCR๋ก ํ
์คํธ ์ถ์ถ"""
|
| 130 |
+
try:
|
| 131 |
+
# PIL๋ก ์ด๋ฏธ์ง ์ด๊ธฐ
|
| 132 |
+
image = Image.open(image_file)
|
| 133 |
+
|
| 134 |
+
# ๊ฐ๋จํ OCR (์ค์ ๋ก๋ ๋ ์ ๊ตํ OCR ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ ํ์)
|
| 135 |
+
# ์ฌ๊ธฐ์๋ ์ด๋ฏธ์ง ์ ๋ณด๋ง ๋ฐํ
|
| 136 |
+
return f"์ด๋ฏธ์ง ํ์ผ: {image.size[0]}x{image.size[1]} ํฝ์
"
|
| 137 |
+
except Exception as e:
|
| 138 |
+
return f"์ด๋ฏธ์ง ์ฝ๊ธฐ ์ค๋ฅ: {str(e)}"
|
| 139 |
+
|
| 140 |
+
def process_uploaded_file(file):
|
| 141 |
+
"""์
๋ก๋๋ ํ์ผ ์ฒ๋ฆฌ"""
|
| 142 |
+
if file is None:
|
| 143 |
+
return None, None
|
| 144 |
+
|
| 145 |
+
file_path = file.name
|
| 146 |
+
file_extension = file_path.lower().split('.')[-1]
|
| 147 |
+
|
| 148 |
+
if file_extension == 'pdf':
|
| 149 |
+
text_content = extract_text_from_pdf(file)
|
| 150 |
+
return text_content, None
|
| 151 |
+
elif file_extension in ['png', 'jpg', 'jpeg']:
|
| 152 |
+
text_content = extract_text_from_image(file)
|
| 153 |
+
return text_content, file
|
| 154 |
+
else:
|
| 155 |
+
return f"์ง์ํ์ง ์๋ ํ์ผ ํ์: {file_extension}", None
|
| 156 |
+
|
| 157 |
+
def chat_with_model(message, history, file=None):
|
| 158 |
+
print(f"๐ DEBUG: chat_with_model ์์")
|
| 159 |
+
print(f" ๋ฉ์์ง: {message}")
|
| 160 |
+
print(f" ํ์ผ: {file}")
|
| 161 |
+
print(f" MODEL_LOADED: {MODEL_LOADED}")
|
| 162 |
+
|
| 163 |
if not MODEL_LOADED:
|
| 164 |
+
print("โ DEBUG: ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์")
|
| 165 |
return "โ ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์์ต๋๋ค."
|
| 166 |
+
|
| 167 |
try:
|
| 168 |
+
print("๐ DEBUG: ํ์ผ ์ฒ๋ฆฌ ์์")
|
| 169 |
+
# ํ์ผ ์ฒ๋ฆฌ
|
| 170 |
+
file_content = ""
|
| 171 |
+
image_file = None
|
| 172 |
+
if file is not None:
|
| 173 |
+
print(f" ํ์ผ๋ช
: {file.name}")
|
| 174 |
+
text_content, image_file = process_uploaded_file(file)
|
| 175 |
+
print(f" ํ
์คํธ ๋ด์ฉ: {text_content[:100] if text_content else 'None'}...")
|
| 176 |
+
print(f" ์ด๋ฏธ์ง ํ์ผ: {image_file}")
|
| 177 |
+
if text_content:
|
| 178 |
+
file_content = f"\n[์
๋ก๋๋ ํ์ผ ๋ด์ฉ]\n{text_content}\n"
|
| 179 |
+
|
| 180 |
+
# ๋ฉ์์ง์ ํ์ผ ๋ด์ฉ ์ถ๊ฐ
|
| 181 |
+
full_message = message + file_content
|
| 182 |
+
print(f"๐ DEBUG: ์ ์ฒด ๋ฉ์์ง: {full_message[:200]}...")
|
| 183 |
|
| 184 |
+
print("๐ค DEBUG: ํ ํฌ๋์ด์ ์ฒ๋ฆฌ ์์")
|
| 185 |
+
inputs = tokenizer(full_message, return_tensors="pt")
|
| 186 |
+
print(f" ์
๋ ฅ shape: {inputs['input_ids'].shape}")
|
| 187 |
+
print(f" attention_mask shape: {inputs['attention_mask'].shape}")
|
| 188 |
+
|
| 189 |
+
print("๐ค DEBUG: ๋ชจ๋ธ ์ถ๋ก ์์")
|
| 190 |
with torch.no_grad():
|
| 191 |
+
if image_file is not None:
|
| 192 |
+
print("๐ผ๏ธ DEBUG: ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ชจ๋")
|
| 193 |
# ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฉํฐ๋ชจ๋ฌ ์์ฑ
|
|
|
|
| 194 |
import torchvision.transforms as transforms
|
| 195 |
|
| 196 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
|
|
|
| 200 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 201 |
])
|
| 202 |
|
| 203 |
+
pil_image = Image.open(image_file).convert('RGB')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
pixel_values = transform(pil_image).unsqueeze(0)
|
| 205 |
image_metas = {"vision_grid_thw": torch.tensor([[1, 14, 14]])} # ๊ธฐ๋ณธ ๊ทธ๋ฆฌ๋ ํฌ๊ธฐ
|
| 206 |
|
| 207 |
+
print(f" ์ด๋ฏธ์ง shape: {pixel_values.shape}")
|
| 208 |
+
print(f" ์ด๋ฏธ์ง ๋ฉํ: {image_metas}")
|
| 209 |
+
|
| 210 |
# ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ์ forward ๋ฉ์๋ ์ฌ์ฉ
|
| 211 |
+
print("๐ DEBUG: ๋ชจ๋ธ ํธ์ถ (๋ฉํฐ๋ชจ๋ฌ)")
|
| 212 |
+
try:
|
| 213 |
+
outputs = model(
|
| 214 |
+
input_ids=inputs["input_ids"],
|
| 215 |
+
attention_mask=inputs["attention_mask"],
|
| 216 |
+
pixel_values=[pixel_values],
|
| 217 |
+
image_metas=image_metas,
|
| 218 |
+
max_new_tokens=200,
|
| 219 |
+
temperature=0.7,
|
| 220 |
+
do_sample=True,
|
| 221 |
+
pad_token_id=tokenizer.eos_token_id
|
| 222 |
+
)
|
| 223 |
+
print("โ
DEBUG: ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ ํธ์ถ ์ฑ๊ณต")
|
| 224 |
+
except Exception as model_error:
|
| 225 |
+
print(f"โ DEBUG: ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ ํธ์ถ ์คํจ: {model_error}")
|
| 226 |
+
print(f" ์ค๋ฅ ํ์
: {type(model_error).__name__}")
|
| 227 |
+
raise model_error
|
| 228 |
else:
|
| 229 |
+
print("๐ DEBUG: ํ
์คํธ๋ง ์ฒ๋ฆฌ ๋ชจ๋")
|
| 230 |
+
# ํ
์คํธ๋ง ์์ฑ
|
| 231 |
+
print("๐ DEBUG: ๋ชจ๋ธ ํธ์ถ (ํ
์คํธ๋ง)")
|
| 232 |
+
try:
|
| 233 |
+
outputs = model(
|
| 234 |
+
input_ids=inputs["input_ids"],
|
| 235 |
+
attention_mask=inputs["attention_mask"],
|
| 236 |
+
max_new_tokens=200,
|
| 237 |
+
temperature=0.7,
|
| 238 |
+
do_sample=True,
|
| 239 |
+
pad_token_id=tokenizer.eos_token_id
|
| 240 |
+
)
|
| 241 |
+
print("โ
DEBUG: ํ
์คํธ ๋ชจ๋ธ ํธ์ถ ์ฑ๊ณต")
|
| 242 |
+
except Exception as model_error:
|
| 243 |
+
print(f"โ DEBUG: ํ
์คํธ ๋ชจ๋ธ ํธ์ถ ์คํจ: {model_error}")
|
| 244 |
+
print(f" ์ค๋ฅ ํ์
: {type(model_error).__name__}")
|
| 245 |
+
raise model_error
|
| 246 |
+
|
| 247 |
+
print("๐ DEBUG: ์ถ๋ ฅ ์ฒ๋ฆฌ ์์")
|
| 248 |
+
print(f" outputs ํ์
: {type(outputs)}")
|
| 249 |
+
print(f" outputs ๋ด์ฉ: {outputs}")
|
| 250 |
|
| 251 |
# outputs๊ฐ ํํ์ธ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์์ ์ฌ์ฉ
|
| 252 |
if isinstance(outputs, tuple):
|
| 253 |
+
print("๐ฆ DEBUG: outputs๊ฐ ํํ์")
|
| 254 |
logits = outputs[0]
|
| 255 |
+
print(f" logits shape: {logits.shape}")
|
| 256 |
else:
|
| 257 |
+
print("๐ฆ DEBUG: outputs๊ฐ ๊ฐ์ฒด์")
|
| 258 |
+
if hasattr(outputs, 'logits'):
|
| 259 |
+
logits = outputs.logits
|
| 260 |
+
print(f" logits shape: {logits.shape}")
|
| 261 |
+
else:
|
| 262 |
+
logits = outputs
|
| 263 |
+
print(f" outputs shape: {logits.shape}")
|
| 264 |
|
| 265 |
+
print("๐ฏ DEBUG: ํ ํฐ ์์ฑ ์๏ฟฝ๏ฟฝ")
|
| 266 |
# ๊ฐ์ฅ ๋์ ํ๋ฅ ์ ํ ํฐ ์ ํ
|
| 267 |
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 268 |
generated_tokens = [next_token]
|
| 269 |
+
print(f" ์ฒซ ๋ฒ์งธ ํ ํฐ: {next_token.item()}")
|
| 270 |
|
| 271 |
# ์ถ๊ฐ ํ ํฐ ์์ฑ
|
| 272 |
+
print("๐ DEBUG: ๋ฐ๋ณต ํ ํฐ ์์ฑ ์์")
|
| 273 |
+
for i in range(199): # max_new_tokens - 1
|
| 274 |
+
if i % 50 == 0:
|
| 275 |
+
print(f" ์งํ๋ฅ : {i}/199")
|
| 276 |
+
|
| 277 |
inputs["input_ids"] = torch.cat([inputs["input_ids"], next_token.unsqueeze(-1)], dim=-1)
|
| 278 |
inputs["attention_mask"] = torch.cat([inputs["attention_mask"], torch.ones_like(next_token.unsqueeze(-1))], dim=-1)
|
| 279 |
|
| 280 |
with torch.no_grad():
|
| 281 |
+
try:
|
| 282 |
+
outputs = model(**inputs)
|
| 283 |
+
if isinstance(outputs, tuple):
|
| 284 |
+
logits = outputs[0]
|
| 285 |
+
else:
|
| 286 |
+
logits = outputs.logits if hasattr(outputs, 'logits') else outputs
|
| 287 |
+
|
| 288 |
+
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 289 |
+
generated_tokens.append(next_token)
|
| 290 |
+
|
| 291 |
+
if next_token.item() == tokenizer.eos_token_id:
|
| 292 |
+
print(f" EOS ํ ํฐ ๋ฐ๊ฒฌ: {i}๋ฒ์งธ")
|
| 293 |
+
break
|
| 294 |
+
except Exception as loop_error:
|
| 295 |
+
print(f"โ DEBUG: ํ ํฐ ์์ฑ ๋ฃจํ ์ค๋ฅ (i={i}): {loop_error}")
|
| 296 |
+
raise loop_error
|
| 297 |
|
| 298 |
+
print("๐ค DEBUG: ํ ํฐ ๋์ฝ๋ฉ ์์")
|
| 299 |
# ์์ฑ๋ ํ ํฐ๋ค์ ๋์ฝ๋ฉ
|
| 300 |
generated_ids = torch.cat(generated_tokens, dim=0)
|
| 301 |
response = tokenizer.decode(generated_ids, skip_special_tokens=True)
|
| 302 |
+
print(f" ์๋ณธ ์๋ต: {response[:200]}...")
|
| 303 |
+
|
| 304 |
+
if full_message in response:
|
| 305 |
+
response = response.replace(full_message, "").strip()
|
| 306 |
+
print(f" ์ ๋ฆฌ๋ ์๋ต: {response[:200]}...")
|
| 307 |
|
| 308 |
+
print("โ
DEBUG: chat_with_model ์๋ฃ")
|
|
|
|
| 309 |
return response if response else "์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ ์ ์์ต๋๋ค."
|
| 310 |
except Exception as e:
|
| 311 |
+
print(f"โ DEBUG: chat_with_model ์ ์ฒด ์ค๋ฅ: {e}")
|
| 312 |
+
print(f" ์ค๋ฅ ํ์
: {type(e).__name__}")
|
| 313 |
+
import traceback
|
| 314 |
+
traceback.print_exc()
|
| 315 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 316 |
|
| 317 |
+
def solve_math_problem(problem, file=None):
|
| 318 |
+
print(f"๐ DEBUG: solve_math_problem ์์")
|
| 319 |
+
print(f" ๋ฌธ์ : {problem}")
|
| 320 |
+
print(f" ํ์ผ: {file}")
|
| 321 |
+
print(f" MODEL_LOADED: {MODEL_LOADED}")
|
| 322 |
+
|
| 323 |
if not MODEL_LOADED:
|
| 324 |
+
print("โ DEBUG: ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์")
|
| 325 |
return "โ ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์์ต๋๋ค."
|
| 326 |
+
|
| 327 |
try:
|
| 328 |
+
print("๐ DEBUG: ํ์ผ ์ฒ๋ฆฌ ์์")
|
| 329 |
+
# ํ์ผ ์ฒ๋ฆฌ
|
| 330 |
+
file_content = ""
|
| 331 |
+
image_file = None
|
| 332 |
+
if file is not None:
|
| 333 |
+
print(f" ํ์ผ๋ช
: {file.name}")
|
| 334 |
+
text_content, image_file = process_uploaded_file(file)
|
| 335 |
+
print(f" ํ
์คํธ ๋ด์ฉ: {text_content[:100] if text_content else 'None'}...")
|
| 336 |
+
print(f" ์ด๋ฏธ์ง ํ์ผ: {image_file}")
|
| 337 |
+
if text_content:
|
| 338 |
+
file_content = f"\n[์
๋ก๋๋ ํ์ผ ๋ด์ฉ]\n{text_content}\n"
|
| 339 |
+
|
| 340 |
+
# ๋ฉ์์ง์ ํ์ผ ๋ด์ฉ ์ถ๊ฐ
|
| 341 |
+
full_prompt = f"๋ค์ ์ํ ๋ฌธ์ ๋ฅผ ๋จ๊ณ๋ณ๋ก ํ์ด์ฃผ์ธ์: {problem}{file_content}"
|
| 342 |
+
print(f"๐ DEBUG: ์ ์ฒด ํ๋กฌํํธ: {full_prompt[:200]}...")
|
| 343 |
+
|
| 344 |
+
print("๐ค DEBUG: ํ ํฌ๋์ด์ ์ฒ๋ฆฌ ์์")
|
| 345 |
+
inputs = tokenizer(full_prompt, return_tensors="pt")
|
| 346 |
+
print(f" ์
๋ ฅ shape: {inputs['input_ids'].shape}")
|
| 347 |
+
print(f" attention_mask shape: {inputs['attention_mask'].shape}")
|
| 348 |
|
| 349 |
+
print("๐ค DEBUG: ๋ชจ๋ธ ์ถ๋ก ์์")
|
| 350 |
with torch.no_grad():
|
| 351 |
+
if image_file is not None:
|
| 352 |
+
print("๐ผ๏ธ DEBUG: ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ชจ๋")
|
| 353 |
# ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฉํฐ๋ชจ๋ฌ ์์ฑ
|
|
|
|
| 354 |
import torchvision.transforms as transforms
|
| 355 |
|
| 356 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
|
|
|
| 360 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 361 |
])
|
| 362 |
|
| 363 |
+
pil_image = Image.open(image_file).convert('RGB')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
pixel_values = transform(pil_image).unsqueeze(0)
|
| 365 |
image_metas = {"vision_grid_thw": torch.tensor([[1, 14, 14]])} # ๊ธฐ๋ณธ ๊ทธ๋ฆฌ๋ ํฌ๊ธฐ
|
| 366 |
|
| 367 |
+
print(f" ์ด๋ฏธ์ง shape: {pixel_values.shape}")
|
| 368 |
+
print(f" ์ด๋ฏธ์ง ๋ฉํ: {image_metas}")
|
| 369 |
+
|
| 370 |
# ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ์ forward ๋ฉ์๋ ์ฌ์ฉ
|
| 371 |
+
print("๐ DEBUG: ๋ชจ๋ธ ํธ์ถ (๋ฉํฐ๋ชจ๋ฌ)")
|
| 372 |
+
try:
|
| 373 |
+
outputs = model(
|
| 374 |
+
input_ids=inputs["input_ids"],
|
| 375 |
+
attention_mask=inputs["attention_mask"],
|
| 376 |
+
pixel_values=[pixel_values],
|
| 377 |
+
image_metas=image_metas,
|
| 378 |
+
max_new_tokens=300,
|
| 379 |
+
temperature=0.3,
|
| 380 |
+
do_sample=True,
|
| 381 |
+
pad_token_id=tokenizer.eos_token_id
|
| 382 |
+
)
|
| 383 |
+
print("โ
DEBUG: ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ ํธ์ถ ์ฑ๊ณต")
|
| 384 |
+
except Exception as model_error:
|
| 385 |
+
print(f"โ DEBUG: ๋ฉํฐ๋ชจ๋ฌ ๋ชจ๋ธ ํธ์ถ ์คํจ: {model_error}")
|
| 386 |
+
print(f" ์ค๋ฅ ํ์
: {type(model_error).__name__}")
|
| 387 |
+
raise model_error
|
| 388 |
else:
|
| 389 |
+
print("๐ DEBUG: ํ
์คํธ๋ง ์ฒ๋ฆฌ ๋ชจ๋")
|
| 390 |
+
# ํ
์คํธ๋ง ์์ฑ
|
| 391 |
+
print("๐ DEBUG: ๋ชจ๋ธ ํธ์ถ (ํ
์คํธ๋ง)")
|
| 392 |
+
try:
|
| 393 |
+
outputs = model(
|
| 394 |
+
input_ids=inputs["input_ids"],
|
| 395 |
+
attention_mask=inputs["attention_mask"],
|
| 396 |
+
max_new_tokens=300,
|
| 397 |
+
temperature=0.3,
|
| 398 |
+
do_sample=True,
|
| 399 |
+
pad_token_id=tokenizer.eos_token_id
|
| 400 |
+
)
|
| 401 |
+
print("โ
DEBUG: ํ
์คํธ ๋ชจ๋ธ ํธ์ถ ์ฑ๊ณต")
|
| 402 |
+
except Exception as model_error:
|
| 403 |
+
print(f"โ DEBUG: ํ
์คํธ ๋ชจ๋ธ ํธ์ถ ์คํจ: {model_error}")
|
| 404 |
+
print(f" ์ค๋ฅ ํ์
: {type(model_error).__name__}")
|
| 405 |
+
raise model_error
|
| 406 |
+
|
| 407 |
+
print("๐ DEBUG: ์ถ๋ ฅ ์ฒ๋ฆฌ ์์")
|
| 408 |
+
print(f" outputs ํ์
: {type(outputs)}")
|
| 409 |
+
print(f" outputs ๋ด์ฉ: {outputs}")
|
| 410 |
|
| 411 |
# outputs๊ฐ ํํ์ธ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์์ ์ฌ์ฉ
|
| 412 |
if isinstance(outputs, tuple):
|
| 413 |
+
print("๐ฆ DEBUG: outputs๊ฐ ํํ์")
|
| 414 |
logits = outputs[0]
|
| 415 |
+
print(f" logits shape: {logits.shape}")
|
| 416 |
else:
|
| 417 |
+
print("๐ฆ DEBUG: outputs๊ฐ ๊ฐ์ฒด์")
|
| 418 |
+
if hasattr(outputs, 'logits'):
|
| 419 |
+
logits = outputs.logits
|
| 420 |
+
print(f" logits shape: {logits.shape}")
|
| 421 |
+
else:
|
| 422 |
+
logits = outputs
|
| 423 |
+
print(f" outputs shape: {logits.shape}")
|
| 424 |
|
| 425 |
+
print("๐ฏ DEBUG: ํ ํฐ ์์ฑ ์์")
|
| 426 |
# ๊ฐ์ฅ ๋์ ํ๋ฅ ์ ํ ํฐ ์ ํ
|
| 427 |
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 428 |
generated_tokens = [next_token]
|
| 429 |
+
print(f" ์ฒซ ๋ฒ์งธ ํ ํฐ: {next_token.item()}")
|
| 430 |
|
| 431 |
# ์ถ๊ฐ ํ ํฐ ์์ฑ
|
| 432 |
+
print("๐ DEBUG: ๋ฐ๋ณต ํ ํฐ ์์ฑ ์์")
|
| 433 |
+
for i in range(299): # max_new_tokens - 1
|
| 434 |
+
if i % 50 == 0:
|
| 435 |
+
print(f" ์งํ๋ฅ : {i}/299")
|
| 436 |
+
|
| 437 |
inputs["input_ids"] = torch.cat([inputs["input_ids"], next_token.unsqueeze(-1)], dim=-1)
|
| 438 |
inputs["attention_mask"] = torch.cat([inputs["attention_mask"], torch.ones_like(next_token.unsqueeze(-1))], dim=-1)
|
| 439 |
|
| 440 |
with torch.no_grad():
|
| 441 |
+
try:
|
| 442 |
+
outputs = model(**inputs)
|
| 443 |
+
if isinstance(outputs, tuple):
|
| 444 |
+
logits = outputs[0]
|
| 445 |
+
else:
|
| 446 |
+
logits = outputs.logits if hasattr(outputs, 'logits') else outputs
|
| 447 |
+
|
| 448 |
+
next_token = torch.argmax(logits[:, -1, :], dim=-1)
|
| 449 |
+
generated_tokens.append(next_token)
|
| 450 |
+
|
| 451 |
+
if next_token.item() == tokenizer.eos_token_id:
|
| 452 |
+
print(f" EOS ํ ํฐ ๋ฐ๊ฒฌ: {i}๋ฒ์งธ")
|
| 453 |
+
break
|
| 454 |
+
except Exception as loop_error:
|
| 455 |
+
print(f"โ DEBUG: ํ ํฐ ์์ฑ ๋ฃจํ ์ค๋ฅ (i={i}): {loop_error}")
|
| 456 |
+
raise loop_error
|
| 457 |
|
| 458 |
+
print("๐ค DEBUG: ํ ํฐ ๋์ฝ๋ฉ ์์")
|
| 459 |
# ์์ฑ๋ ํ ํฐ๋ค์ ๋์ฝ๋ฉ
|
| 460 |
generated_ids = torch.cat(generated_tokens, dim=0)
|
| 461 |
response = tokenizer.decode(generated_ids, skip_special_tokens=True)
|
| 462 |
+
print(f" ์๋ณธ ์๋ต: {response[:200]}...")
|
| 463 |
+
|
| 464 |
+
if full_prompt in response:
|
| 465 |
+
response = response.replace(full_prompt, "").strip()
|
| 466 |
+
print(f" ์ ๋ฆฌ๋ ์๋ต: {response[:200]}...")
|
| 467 |
|
| 468 |
+
print("โ
DEBUG: solve_math_problem ์๋ฃ")
|
|
|
|
| 469 |
return response if response else "์ฃ์กํฉ๋๋ค. ์ํ ๋ฌธ์ ๋ฅผ ํ ์ ์์ต๋๋ค."
|
| 470 |
except Exception as e:
|
| 471 |
+
print(f"โ DEBUG: solve_math_problem ์ ์ฒด ์ค๋ฅ: {e}")
|
| 472 |
+
print(f" ์ค๋ฅ ํ์
: {type(e).__name__}")
|
| 473 |
+
import traceback
|
| 474 |
+
traceback.print_exc()
|
| 475 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 476 |
|
| 477 |
with gr.Blocks(title="Lily Math RAG System", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 485 |
msg = gr.Textbox(label="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์", placeholder="์๋
ํ์ธ์! ์ํ ๋ฌธ์ ๋ฅผ ๋์์ฃผ์ธ์.", lines=2)
|
| 486 |
clear = gr.Button("๋ํ ์ด๊ธฐํ")
|
| 487 |
with gr.Column(scale=1):
|
| 488 |
+
gr.Markdown("### ๐ ํ์ผ ์
๋ก๋")
|
| 489 |
+
file_input = gr.File(label="PDF/์ด๋ฏธ์ง ํ์ผ (์ ํ์ฌํญ)", file_types=[".pdf", ".png", ".jpg", ".jpeg"])
|
| 490 |
+
gr.Markdown("PDF๋ ์ด๋ฏธ์ง ํ์ผ์ ์
๋ก๋ํ๋ฉด ๋ฌธ์๋ฅผ ํด์ํ์ฌ ๋ต๋ณํฉ๋๋ค.")
|
| 491 |
|
| 492 |
+
def respond(message, chat_history, file):
|
| 493 |
+
bot_message = chat_with_model(message, chat_history, file)
|
| 494 |
chat_history.append({"role": "user", "content": message})
|
| 495 |
chat_history.append({"role": "assistant", "content": bot_message})
|
| 496 |
return "", chat_history
|
| 497 |
+
msg.submit(respond, [msg, chatbot, file_input], [msg, chatbot])
|
| 498 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 499 |
|
| 500 |
with gr.Tab("๐งฎ ์ํ ๋ฌธ์ ํด๊ฒฐ"):
|
|
|
|
| 503 |
math_input = gr.Textbox(label="์ํ ๋ฌธ์ ", placeholder="์: 2x + 5 = 13", lines=3)
|
| 504 |
solve_btn = gr.Button("๋ฌธ์ ํ๊ธฐ", variant="primary")
|
| 505 |
with gr.Column(scale=1):
|
| 506 |
+
gr.Markdown("### ๐ ํ์ผ ์
๋ก๋")
|
| 507 |
+
math_file_input = gr.File(label="์ํ ๋ฌธ์ ํ์ผ (์ ํ์ฌํญ)", file_types=[".pdf", ".png", ".jpg", ".jpeg"])
|
| 508 |
+
gr.Markdown("์ํ ๋ฌธ์ PDF๋ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ๋ ์ ํํ ๋ต๋ณ์ ๋ฐ์ ์ ์์ต๋๋ค.")
|
| 509 |
with gr.Column(scale=2):
|
| 510 |
math_output = gr.Textbox(label="ํด๋ต", lines=8, interactive=False)
|
| 511 |
+
solve_btn.click(solve_math_problem, [math_input, math_file_input], math_output)
|
| 512 |
|
| 513 |
with gr.Tab("โ๏ธ ์ค์ "):
|
| 514 |
gr.Markdown("## ์์คํ
์ ๋ณด")
|
requirements.txt
CHANGED
|
@@ -8,3 +8,4 @@ python-dotenv>=1.0.0
|
|
| 8 |
Pillow>=9.0.0
|
| 9 |
torchvision>=0.15.0
|
| 10 |
accelerate==1.9.0
|
|
|
|
|
|
| 8 |
Pillow>=9.0.0
|
| 9 |
torchvision>=0.15.0
|
| 10 |
accelerate==1.9.0
|
| 11 |
+
PyMuPDF>=1.23.0
|