Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
TenAI PMAI Pro - ๊ธฐ์
์์ฐ๊ด๋ฆฌ AI ํ๋ซํผ
|
| 3 |
+
Zero Hardware | Data Monopoly | AI Transformation
|
| 4 |
+
Fireworks Vision API + Groq LLM
|
| 5 |
+
"""
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import requests
|
| 8 |
+
import os, json, base64, re
|
| 9 |
+
from typing import Generator, Optional, List, Dict
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
try:
|
| 13 |
+
import fitz
|
| 14 |
+
PDF_AVAILABLE = True
|
| 15 |
+
except ImportError:
|
| 16 |
+
PDF_AVAILABLE = False
|
| 17 |
+
try:
|
| 18 |
+
from PIL import Image
|
| 19 |
+
IMAGE_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
IMAGE_AVAILABLE = False
|
| 22 |
+
try:
|
| 23 |
+
import folium
|
| 24 |
+
from folium.plugins import HeatMap
|
| 25 |
+
FOLIUM_AVAILABLE = True
|
| 26 |
+
except ImportError:
|
| 27 |
+
FOLIUM_AVAILABLE = False
|
| 28 |
+
try:
|
| 29 |
+
import plotly.express as px
|
| 30 |
+
import plotly.graph_objects as go
|
| 31 |
+
PLOTLY_AVAILABLE = True
|
| 32 |
+
except ImportError:
|
| 33 |
+
PLOTLY_AVAILABLE = False
|
| 34 |
+
try:
|
| 35 |
+
from datasets import load_dataset
|
| 36 |
+
DATASETS_AVAILABLE = True
|
| 37 |
+
except ImportError:
|
| 38 |
+
DATASETS_AVAILABLE = False
|
| 39 |
+
FIREWORKS_API_KEY = os.environ.get("FIREWORKS_API_KEY", "")
|
| 40 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
| 41 |
+
FIREWORKS_VISION_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 42 |
+
FIREWORKS_VISION_MODEL = "accounts/fireworks/models/qwen3-vl-235b-a22b-thinking"
|
| 43 |
+
DEMO_MODE = not FIREWORKS_API_KEY and not GROQ_API_KEY
|
| 44 |
+
groq_client = None
|
| 45 |
+
if GROQ_API_KEY:
|
| 46 |
+
try:
|
| 47 |
+
from groq import Groq
|
| 48 |
+
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 49 |
+
except:
|
| 50 |
+
pass
|
| 51 |
+
PMAI_SYSTEM_PROMPT = """๋น์ ์ TenAI์ PMAI(Property Management AI)์
๋๋ค. ๊ธฐ์
์์ฐ๊ด๋ฆฌ๋ฅผ ์ํ 24์๊ฐ AI ๋น์์
๋๋ค.
|
| 52 |
+
ํต์ฌ ์ญ๋: Vision AI + RAG + ์ถ๋ก ์์ง ๊ธฐ๋ฐ ๋ฌธ์ ๋ถ์, ๋น์ ํ ๋ฌธ์์ ๋๋ฉด ์ดํด
|
| 53 |
+
์ ๊ณต ๊ฐ์น: AMC(์์ฐ์ด์ฉ)-์ค์๊ฐ ๊ฐ์นํ๊ฐ, PMC(์๋๊ด๋ฆฌ)-๊ณต์ค๊ด๋ฆฌ ์๋ํ, FMC(์์ค๊ด๋ฆฌ)-์์ค์ ๊ฒ ์๋ํ
|
| 54 |
+
ํน์ง: Zero Hardware-์ผ์ ์์ด ์ฆ์ ๋์
, ๋ฌธ์ ๊ธฐ๋ฐ ๋ถ์, ๋น์ฉ ์ ๊ฐ & ์์ต ์ฆ๋
|
| 55 |
+
ํ๊ตญ์ด๋ก ์น์ ํ๊ณ ์ ๋ฌธ์ ์ผ๋ก ์๋ตํ์ธ์."""
|
| 56 |
+
DOCUMENT_ANALYSIS_PROMPT = """๋น์ ์ TenAI์ ๋ฌธ์ ๋ถ์ AI์
๋๋ค. ์
๋ก๋๋ ๋ฌธ์๋ฅผ ๋ถ์ํ์ฌ:
|
| 57 |
+
1. ํต์ฌ ์ ๋ณด ์ถ์ถ 2. ์ ์ฌ์ ๋ฆฌ์คํฌ ์๋ณ 3. ๋น์ฉ ์ต์ ํ ํฌ์ธํธ ๋์ถ 4. ์คํ ๊ฐ๋ฅํ ์ธ์ฌ์ดํธ ์ ๊ณต"""
|
| 58 |
+
COST_ANALYSIS_PROMPT = """๋น์ ์ TenAI์ ๋น์ฉ ๋ถ์ AI์
๋๋ค. ์ด์๋น์ฉ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ:
|
| 59 |
+
1. ๋น์ฉ ๊ตฌ์กฐ ๋ถ์ 2. ๋์ ์ง์ ์๋ณ 3. ์ ๊ฐ ๊ฐ๋ฅ ํญ๋ชฉ ๋์ถ 4. ROI ๊ธฐ๋ฐ ์ฐ์ ์์ ์ ์"""
|
| 60 |
+
SOMA_AGENTS = {
|
| 61 |
+
"coordinator": {"name": "๐ฏ ์ข
ํฉ ์ฝ๋๋ค์ดํฐ", "role": "SOMA ํ์ฅ", "prompt": "๋น์ ์ SOMA ํ์ ์ข
ํฉ ์ฝ๋๋ค์ดํฐ์
๋๋ค. ๊ฐ ์ ๋ฌธ๊ฐ์ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์ข
ํฉํ์ฌ Executive Summary๋ฅผ ์์ฑํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."},
|
| 62 |
+
"document_analyst": {"name": "๐ ๋ฌธ์ ๋ถ์๊ฐ", "role": "๋ฌธ์/๊ณ์ฝ์ ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ๋ฌธ์ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์๋์ฐจ๊ณ์ฝ์, ์ ์ง๋ณด์ ๊ณ์ฝ ๋ฑ์ ์ ๋ฐ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."},
|
| 63 |
+
"financial_expert": {"name": "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ", "role": "๋น์ฉ/์์ต ๋ถ์", "prompt": "๋น์ ์ SOMA ํ์ ์ฌ๋ฌด ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ๋ฌด์ ์ํฅ์ ๋ถ์ํ๊ณ ๋น์ฉ ์ ๊ฐ ๋ฐฉ์์ ์ ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."},
|
| 64 |
+
"legal_advisor": {"name": "โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ", "role": "๋ฒ์ ๋ฆฌ์คํฌ ๊ฒํ ", "prompt": "๋น์ ์ SOMA ํ์ ๋ฒ๋ฅ ์๋ฌธ ์ ๋ฌธ๊ฐ์
๋๋ค. ๋ฒ์ ๋ฆฌ์คํฌ, ๋ถ๋ฆฌํ ์กฐํญ์ ์๋ณํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."},
|
| 65 |
+
"facility_manager": {"name": "๐ง ์์ค ๊ด๋ฆฌ์", "role": "์ด์/์์ค ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ์์ค ๊ด๋ฆฌ ์ ๋ฌธ๊ฐ์
๋๋ค. ์์ค ์ด์ ๊ด์ ์์ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."},
|
| 66 |
+
"market_analyst": {"name": "๐ ์๊ถ ๋ถ์๊ฐ", "role": "์
์ง/์๊ถ ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ์๊ถ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
์ง, ์ฃผ๋ณ ์๊ถ, ์ ๋์ธ๊ตฌ๋ฅผ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}
|
| 67 |
+
}
|
| 68 |
+
SEOUL_DISTRICTS = {
|
| 69 |
+
"๊ฐ๋จ๊ตฌ": {"lat": 37.5172, "lng": 127.0473, "ํน์ฑ": "IT/๊ธ์ต ์ค์ฌ, ๊ณ ๊ธ ์คํผ์ค", "ํ๊ท ์๋๋ฃ": 85000},
|
| 70 |
+
"์์ด๊ตฌ": {"lat": 37.4837, "lng": 127.0324, "ํน์ฑ": "๋ฒ์กฐํ์ด, ๊ต์ก/๋ฌธํ", "ํ๊ท ์๋๋ฃ": 75000},
|
| 71 |
+
"์กํ๊ตฌ": {"lat": 37.5145, "lng": 127.1050, "ํน์ฑ": "์ ์ค ์๊ถ, ์ฃผ๊ฑฐ/์์
๋ณตํฉ", "ํ๊ท ์๋๋ฃ": 65000},
|
| 72 |
+
"๋งํฌ๊ตฌ": {"lat": 37.5663, "lng": 126.9014, "ํน์ฑ": "ํ๋/ํฉ์ ์๊ถ, ๋ฌธํ/์์ ", "ํ๊ท ์๋๋ฃ": 55000},
|
| 73 |
+
"์๋ฑํฌ๊ตฌ": {"lat": 37.5264, "lng": 126.8963, "ํน์ฑ": "์ฌ์๋ ๊ธ์ต, ํ์์คํ์ด", "ํ๊ท ์๋๋ฃ": 70000},
|
| 74 |
+
"์ฉ์ฐ๊ตฌ": {"lat": 37.5324, "lng": 126.9903, "ํน์ฑ": "์ดํ์/ํ๋จ, ์ฌ๊ฐ๋ฐ", "ํ๊ท ์๋๋ฃ": 60000},
|
| 75 |
+
"์ฑ๋๊ตฌ": {"lat": 37.5634, "lng": 127.0369, "ํน์ฑ": "์ฑ์๋ ํซํ, ์ง์์ฐ์
", "ํ๊ท ์๋๋ฃ": 55000},
|
| 76 |
+
"์ข
๋ก๊ตฌ": {"lat": 37.5735, "lng": 126.9790, "ํน์ฑ": "๋์ฌ CBD, ์ ํต ์๊ถ", "ํ๊ท ์๋๋ฃ": 80000},
|
| 77 |
+
"์ค๊ตฌ": {"lat": 37.5641, "lng": 126.9979, "ํน์ฑ": "๋ช
๋/์์ง๋ก, ๏ฟฝ๏ฟฝ๊ด/์์
", "ํ๊ท ์๋๋ฃ": 90000},
|
| 78 |
+
"๊ฐ์๊ตฌ": {"lat": 37.5510, "lng": 126.8495, "ํน์ฑ": "๋ง๊ณก์ง๊ตฌ, ์ฐ์
๋จ์ง", "ํ๊ท ์๋๋ฃ": 45000},
|
| 79 |
+
"๊ตฌ๋ก๊ตฌ": {"lat": 37.4954, "lng": 126.8874, "ํน์ฑ": "๋์งํธ๋จ์ง, ์ฐ์
", "ํ๊ท ์๋๋ฃ": 40000},
|
| 80 |
+
"๊ธ์ฒ๊ตฌ": {"lat": 37.4569, "lng": 126.8956, "ํน์ฑ": "๊ฐ์ฐ๋์งํธ, IT", "ํ๊ท ์๋๋ฃ": 38000},
|
| 81 |
+
}
|
| 82 |
+
MARKET_REGIONS = {'์์ธ': '์์ธ_202506', '๊ฒฝ๊ธฐ': '๊ฒฝ๊ธฐ_202506', '๋ถ์ฐ': '๋ถ์ฐ_202506', '๋๊ตฌ': '๋๊ตฌ_202506', '์ธ์ฒ': '์ธ์ฒ_202506', '๊ด์ฃผ': '๊ด์ฃผ_202506', '๋์ ': '๋์ _202506', '์ธ์ฐ': '์ธ์ฐ_202506', '์ธ์ข
': '์ธ์ข
_202506', '๊ฒฝ๋จ': '๊ฒฝ๋จ_202506', '๊ฒฝ๋ถ': '๊ฒฝ๋ถ_202506', '์ ๋จ': '์ ๋จ_202506', '์ ๋ถ': '์ ๋ถ_202506', '์ถฉ๋จ': '์ถฉ๋จ_202506', '์ถฉ๋ถ': '์ถฉ๋ถ_202506', '๊ฐ์': '๊ฐ์_202506', '์ ์ฃผ': '์ ์ฃผ_202506'}
|
| 83 |
+
class MarketDataLoader:
|
| 84 |
+
@staticmethod
|
| 85 |
+
def load_region_data(region: str, sample_size: int = 20000) -> pd.DataFrame:
|
| 86 |
+
if not DATASETS_AVAILABLE:
|
| 87 |
+
return pd.DataFrame()
|
| 88 |
+
try:
|
| 89 |
+
file_name = f"์์๊ณต์ธ์์ฅ์งํฅ๊ณต๋จ_์๊ฐ(์๊ถ)์ ๋ณด_{MARKET_REGIONS[region]}.csv"
|
| 90 |
+
dataset = load_dataset("ginipick/market", data_files=file_name, split="train")
|
| 91 |
+
df = dataset.to_pandas()
|
| 92 |
+
return df.sample(n=min(sample_size, len(df)), random_state=42)
|
| 93 |
+
except:
|
| 94 |
+
return pd.DataFrame()
|
| 95 |
+
@staticmethod
|
| 96 |
+
def load_multiple_regions(regions: List[str], sample_per_region: int = 20000) -> pd.DataFrame:
|
| 97 |
+
dfs = [MarketDataLoader.load_region_data(r, sample_per_region) for r in regions]
|
| 98 |
+
return pd.concat([d for d in dfs if not d.empty], ignore_index=True) if any(not d.empty for d in dfs) else pd.DataFrame()
|
| 99 |
+
class MarketAnalyzer:
|
| 100 |
+
def __init__(self, df: pd.DataFrame):
|
| 101 |
+
self.df = df
|
| 102 |
+
self.prepare_data()
|
| 103 |
+
def prepare_data(self):
|
| 104 |
+
for col in ['๊ฒฝ๋', '์๋']:
|
| 105 |
+
if col in self.df.columns:
|
| 106 |
+
self.df[col] = pd.to_numeric(self.df[col], errors='coerce')
|
| 107 |
+
self.df = self.df.dropna(subset=['๊ฒฝ๋', '์๋'])
|
| 108 |
+
if '์ธต์ ๋ณด' in self.df.columns:
|
| 109 |
+
self.df['์ธต์ ๋ณด_์ซ์'] = self.df['์ธต์ ๋ณด'].apply(self._parse_floor)
|
| 110 |
+
def _parse_floor(self, floor_str):
|
| 111 |
+
if pd.isna(floor_str): return None
|
| 112 |
+
s = str(floor_str)
|
| 113 |
+
if '์งํ' in s or 'B' in s:
|
| 114 |
+
m = re.search(r'\d+', s)
|
| 115 |
+
return -int(m.group()) if m else -1
|
| 116 |
+
m = re.search(r'\d+', s)
|
| 117 |
+
return int(m.group()) if m else None
|
| 118 |
+
def get_summary(self) -> Dict:
|
| 119 |
+
return {
|
| 120 |
+
'์ด์ ํฌ์': len(self.df),
|
| 121 |
+
'์
์ข
์': self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].nunique() if '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' in self.df.columns else 0,
|
| 122 |
+
'์์์
์ข
': self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].value_counts().head(5).to_dict() if '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' in self.df.columns else {},
|
| 123 |
+
}
|
| 124 |
+
def create_category_chart(self):
|
| 125 |
+
if not PLOTLY_AVAILABLE or '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' not in self.df.columns: return None
|
| 126 |
+
top = self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].value_counts().head(15)
|
| 127 |
+
fig = px.bar(x=top.values, y=top.index, orientation='h', title='๐ ์์ ์
์ข
TOP 15', color=top.values, color_continuous_scale='blues')
|
| 128 |
+
fig.update_layout(showlegend=False, height=450)
|
| 129 |
+
return fig
|
| 130 |
+
def create_district_chart(self):
|
| 131 |
+
if not PLOTLY_AVAILABLE or '์๊ตฐ๊ตฌ๋ช
' not in self.df.columns: return None
|
| 132 |
+
counts = self.df['์๊ตฐ๊ตฌ๋ช
'].value_counts().head(15)
|
| 133 |
+
fig = px.bar(x=counts.values, y=counts.index, orientation='h', title='๐ ์ง์ญ๋ณ ์ ํฌ ๋ฐ์ง๋', color=counts.values, color_continuous_scale='reds')
|
| 134 |
+
fig.update_layout(showlegend=False, height=450)
|
| 135 |
+
return fig
|
| 136 |
+
def create_heatmap(self, sample_size: int = 2000) -> str:
|
| 137 |
+
if not FOLIUM_AVAILABLE: return "<p>folium ์ค์น ํ์</p>"
|
| 138 |
+
df_sample = self.df.sample(n=min(sample_size, len(self.df)), random_state=42)
|
| 139 |
+
m = folium.Map(location=[df_sample['์๋'].mean(), df_sample['๊ฒฝ๋'].mean()], zoom_start=11, tiles='cartodbpositron')
|
| 140 |
+
HeatMap([[r['์๋'], r['๊ฒฝ๋']] for _, r in df_sample.iterrows()], radius=15, blur=25).add_to(m)
|
| 141 |
+
return m._repr_html_()
|
| 142 |
+
class AppState:
|
| 143 |
+
def __init__(self):
|
| 144 |
+
self.analyzer = None
|
| 145 |
+
app_state = AppState()
|
| 146 |
+
def encode_image_to_base64(image_path: str) -> str:
|
| 147 |
+
with open(image_path, "rb") as f:
|
| 148 |
+
return base64.b64encode(f.read()).decode('utf-8')
|
| 149 |
+
def get_image_mime_type(file_path: str) -> str:
|
| 150 |
+
ext = file_path.lower().split('.')[-1]
|
| 151 |
+
return {'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'png': 'image/png', 'gif': 'image/gif', 'webp': 'image/webp'}.get(ext, 'image/jpeg')
|
| 152 |
+
def extract_text_from_image_fireworks(image_path: str) -> str:
|
| 153 |
+
"""Fireworks AI Vision API๋ฅผ ์ฌ์ฉํ ์ด๋ฏธ์ง OCR"""
|
| 154 |
+
if not FIREWORKS_API_KEY:
|
| 155 |
+
return """[๋ฐ๋ชจ ๋ชจ๋] ์ด๋ฏธ์ง OCR ๊ฒฐ๊ณผ:
|
| 156 |
+
---
|
| 157 |
+
์๋์ฐจ ๊ณ์ฝ์
|
| 158 |
+
์ 1์กฐ (๋ชฉ์ ) ์๋์ธ์ ๏ฟฝ๏ฟฝ๋ ๋ถ๋์ฐ์ ์์ฐจ์ธ์๊ฒ ์๋ํ๋ค.
|
| 159 |
+
์์ฌ์ง: ์์ธ์ ๊ฐ๋จ๊ตฌ ํ
ํค๋๋ก 123, 5์ธต
|
| 160 |
+
์๋๋ฉด์ : 330.58ใก (100ํ)
|
| 161 |
+
์๋๊ธฐ๊ฐ: 2024.01.01 ~ 2026.12.31 (3๋
)
|
| 162 |
+
๋ณด์ฆ๊ธ: ๊ธ ์ผ์ต์์ (โฉ300,000,000)
|
| 163 |
+
์์๋๋ฃ: ๊ธ ์ผ์ฒ์ค๋ฐฑ๋ง์์ (โฉ15,000,000)
|
| 164 |
+
๊ด๋ฆฌ๋น: ํ๋น 25,000์ (์ 250๋ง์)
|
| 165 |
+
---
|
| 166 |
+
โ ๏ธ FIREWORKS_API_KEY ์ค์ ์ ์ค์ OCR ๊ฒฐ๊ณผ ์ ๊ณต"""
|
| 167 |
+
try:
|
| 168 |
+
base64_image = encode_image_to_base64(image_path)
|
| 169 |
+
mime_type = get_image_mime_type(image_path)
|
| 170 |
+
headers = {
|
| 171 |
+
"Accept": "application/json",
|
| 172 |
+
"Content-Type": "application/json",
|
| 173 |
+
"Authorization": f"Bearer {FIREWORKS_API_KEY}"
|
| 174 |
+
}
|
| 175 |
+
payload = {
|
| 176 |
+
"model": FIREWORKS_VISION_MODEL,
|
| 177 |
+
"max_tokens": 4096,
|
| 178 |
+
"temperature": 0.2,
|
| 179 |
+
"messages": [
|
| 180 |
+
{
|
| 181 |
+
"role": "user",
|
| 182 |
+
"content": [
|
| 183 |
+
{
|
| 184 |
+
"type": "text",
|
| 185 |
+
"text": """์ด ์ด๋ฏธ์ง๋ ๋ถ๋์ฐ ๊ด๋ จ ๋ฌธ์(๊ณ์ฝ์, ๋๋ฉด, ๊ด๋ฆฌ๋ฌธ์ ๋ฑ)์
๋๋ค.
|
| 186 |
+
์ด๋ฏธ์ง์ ์๋ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ ํํ๊ฒ ์ถ์ถํด์ฃผ์ธ์.
|
| 187 |
+
ํ๋ ๋ํ๊ฐ ์๋ค๋ฉด ๊ตฌ์กฐ๋ฅผ ์ ์งํ์ฌ ํ
์คํธ๋ก ๋ณํํด์ฃผ์ธ์.
|
| 188 |
+
ํ๊ตญ์ด์ ์์ด ๋ชจ๋ ์ ํํ๊ฒ ์ธ์ํด์ฃผ์ธ์.
|
| 189 |
+
์ถ์ถํ ํ
์คํธ๋ง ์ถ๋ ฅํ๊ณ , ๋ค๋ฅธ ์ค๋ช
์ ํ์ง ๋ง์ธ์."""
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"type": "image_url",
|
| 193 |
+
"image_url": {
|
| 194 |
+
"url": f"data:{mime_type};base64,{base64_image}"
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
]
|
| 198 |
+
}
|
| 199 |
+
]
|
| 200 |
+
}
|
| 201 |
+
response = requests.post(FIREWORKS_VISION_URL, headers=headers, json=payload, timeout=60)
|
| 202 |
+
if response.status_code == 200:
|
| 203 |
+
result = response.json()
|
| 204 |
+
content = result.get("choices", [{}])[0].get("message", {}).get("content", "")
|
| 205 |
+
if content:
|
| 206 |
+
if "<think>" in content and "</think>" in content:
|
| 207 |
+
content = re.sub(r'<think>.*?</think>', '', content, flags=re.DOTALL).strip()
|
| 208 |
+
return content
|
| 209 |
+
return "โ ๏ธ OCR ๊ฒฐ๊ณผ๊ฐ ๋น์ด์์ต๋๋ค."
|
| 210 |
+
else:
|
| 211 |
+
return f"โ API ์ค๋ฅ ({response.status_code}): {response.text[:200]}"
|
| 212 |
+
except requests.exceptions.Timeout:
|
| 213 |
+
return "โ API ์๋ต ์๊ฐ ์ด๊ณผ. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
| 214 |
+
except Exception as e:
|
| 215 |
+
return f"โ OCR ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}"
|
| 216 |
+
def extract_text_from_pdf(file_path: str) -> str:
|
| 217 |
+
if not PDF_AVAILABLE:
|
| 218 |
+
return "โ PyMuPDF ์ค์น ํ์: pip install pymupdf"
|
| 219 |
+
try:
|
| 220 |
+
doc = fitz.open(file_path)
|
| 221 |
+
texts = [f"--- ํ์ด์ง {i+1} ---\n{page.get_text()}" for i, page in enumerate(doc) if page.get_text().strip()]
|
| 222 |
+
doc.close()
|
| 223 |
+
return "\n\n".join(texts) if texts else "โ ๏ธ ํ
์คํธ ์ถ์ถ ์คํจ (์ด๋ฏธ์ง PDF์ผ ์ ์์)"
|
| 224 |
+
except Exception as e:
|
| 225 |
+
return f"โ PDF ์ค๋ฅ: {e}"
|
| 226 |
+
def generate_response_fireworks(message: str, history: list, system_prompt: str) -> Generator:
|
| 227 |
+
"""Fireworks AI๋ฅผ ์ฌ์ฉํ ํ
์คํธ ์์ฑ (์คํธ๋ฆฌ๋ฐ)"""
|
| 228 |
+
if not FIREWORKS_API_KEY:
|
| 229 |
+
demo = f"""## ๐ข PMAI ๋ถ์ ๊ฒฐ๊ณผ
|
| 230 |
+
**์ง๋ฌธ**: {message}
|
| 231 |
+
---
|
| 232 |
+
### ๐ ๋ถ์ ๋ด์ฉ
|
| 233 |
+
1. **ํํฉ**: ์
๋ ฅ ๋ด์ฉ ๊ธฐ๋ฐ ์์ฐ๊ด๋ฆฌ ๊ด์ ๋ถ์ ์๋ฃ
|
| 234 |
+
2. **ํต์ฌ**: Zero Hardware ์ ๊ทผ, ๋ฌธ์ ๊ธฐ๋ฐ ๋น์ฉ ์ ๊ฐ ํฌ์ธํธ ๋์ถ
|
| 235 |
+
3. **๊ถ์ฅ**: ์ด์๋น์ฉ ๊ตฌ์กฐ ์ฌ๊ฒํ , ์๋์ง ํจ์จํ, ๊ณต์ค๋ฅ ๊ด๋ฆฌ ์ ๋ต
|
| 236 |
+
> โ ๏ธ ๋ฐ๋ชจ ๋ชจ๋ - FIREWORKS_API_KEY ์ค์ ์ ์์ธ ๋ถ์ ์ ๊ณต"""
|
| 237 |
+
for i in range(0, len(demo), 20):
|
| 238 |
+
yield demo[:i+20]
|
| 239 |
+
return
|
| 240 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 241 |
+
for h in history:
|
| 242 |
+
if isinstance(h, (list, tuple)) and len(h) >= 2:
|
| 243 |
+
messages.extend([{"role": "user", "content": str(h[0])}, {"role": "assistant", "content": str(h[1])}])
|
| 244 |
+
messages.append({"role": "user", "content": message})
|
| 245 |
+
headers = {"Accept": "application/json", "Content-Type": "application/json", "Authorization": f"Bearer {FIREWORKS_API_KEY}"}
|
| 246 |
+
payload = {"model": "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507", "max_tokens": 4096, "temperature": 0.7, "stream": True, "messages": messages}
|
| 247 |
+
try:
|
| 248 |
+
response = requests.post(FIREWORKS_VISION_URL, headers=headers, json=payload, stream=True, timeout=60)
|
| 249 |
+
if response.status_code == 200:
|
| 250 |
+
full_response = ""
|
| 251 |
+
for line in response.iter_lines():
|
| 252 |
+
if line:
|
| 253 |
+
line_text = line.decode('utf-8')
|
| 254 |
+
if line_text.startswith('data: '):
|
| 255 |
+
data_str = line_text[6:]
|
| 256 |
+
if data_str.strip() == '[DONE]':
|
| 257 |
+
break
|
| 258 |
+
try:
|
| 259 |
+
data = json.loads(data_str)
|
| 260 |
+
content = data.get('choices', [{}])[0].get('delta', {}).get('content', '')
|
| 261 |
+
if content:
|
| 262 |
+
full_response += content
|
| 263 |
+
clean = re.sub(r'<think>.*?</think>', '', full_response, flags=re.DOTALL).strip()
|
| 264 |
+
yield clean
|
| 265 |
+
except:
|
| 266 |
+
continue
|
| 267 |
+
else:
|
| 268 |
+
yield f"โ API ์ค๋ฅ: {response.status_code}"
|
| 269 |
+
except Exception as e:
|
| 270 |
+
yield f"โ ์ค๋ฅ: {e}"
|
| 271 |
+
def generate_response(message: str, history: list, system_prompt: str = PMAI_SYSTEM_PROMPT) -> Generator:
|
| 272 |
+
"""Groq ๋๋ Fireworks๋ฅผ ์ฌ์ฉํ ์๋ต ์์ฑ"""
|
| 273 |
+
if groq_client:
|
| 274 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 275 |
+
for h in history:
|
| 276 |
+
if isinstance(h, (list, tuple)) and len(h) >= 2:
|
| 277 |
+
messages.extend([{"role": "user", "content": str(h[0])}, {"role": "assistant", "content": str(h[1])}])
|
| 278 |
+
messages.append({"role": "user", "content": message})
|
| 279 |
+
try:
|
| 280 |
+
completion = groq_client.chat.completions.create(model="llama-3.3-70b-versatile", messages=messages, temperature=0.7, max_tokens=4096, stream=True)
|
| 281 |
+
response = ""
|
| 282 |
+
for chunk in completion:
|
| 283 |
+
if chunk.choices[0].delta.content:
|
| 284 |
+
response += chunk.choices[0].delta.content
|
| 285 |
+
yield response
|
| 286 |
+
return
|
| 287 |
+
except:
|
| 288 |
+
pass
|
| 289 |
+
yield from generate_response_fireworks(message, history, system_prompt)
|
| 290 |
+
def chat_respond(message: str, history: list):
|
| 291 |
+
if not message or not message.strip():
|
| 292 |
+
yield history or []
|
| 293 |
+
return
|
| 294 |
+
history = history or []
|
| 295 |
+
history_api = []
|
| 296 |
+
for h in history:
|
| 297 |
+
if isinstance(h, dict):
|
| 298 |
+
r, c = h.get("role", ""), h.get("content", "")
|
| 299 |
+
if r == "user": history_api.append([c, ""])
|
| 300 |
+
elif r == "assistant" and history_api: history_api[-1][1] = c
|
| 301 |
+
new_history = list(history) + [{"role": "user", "content": message}, {"role": "assistant", "content": ""}]
|
| 302 |
+
for chunk in generate_response(message, history_api, PMAI_SYSTEM_PROMPT):
|
| 303 |
+
new_history[-1] = {"role": "assistant", "content": chunk}
|
| 304 |
+
yield new_history
|
| 305 |
+
def run_soma_analysis(document_text: str, selected_agents: List[str]) -> Generator:
|
| 306 |
+
if not document_text.strip():
|
| 307 |
+
yield "๐ ๋ฌธ์ ๋ด์ฉ์ด ํ์ํฉ๋๋ค."
|
| 308 |
+
return
|
| 309 |
+
if not selected_agents:
|
| 310 |
+
selected_agents = ["document_analyst", "financial_expert", "legal_advisor"]
|
| 311 |
+
output = "# ๐ค SOMA ๋ฉํฐ ์์ด์ ํธ ํ์
๋ถ์\n\n---\n\n"
|
| 312 |
+
yield output
|
| 313 |
+
results = {}
|
| 314 |
+
for key in selected_agents:
|
| 315 |
+
agent = SOMA_AGENTS.get(key)
|
| 316 |
+
if not agent: continue
|
| 317 |
+
output += f"## {agent['name']}\n**์ญํ **: {agent['role']}\n\nโณ ๋ถ์ ์ค...\n\n"
|
| 318 |
+
yield output
|
| 319 |
+
prompt = f"{agent['prompt']}\n\n๋ถ์ํ ๋ฌธ์:\n---\n{document_text[:6000]}\n---\n๊ตฌ์ฒด์ ์ธ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํ์ธ์."
|
| 320 |
+
agent_response = ""
|
| 321 |
+
for chunk in generate_response(prompt, [], agent['prompt']):
|
| 322 |
+
agent_response = chunk
|
| 323 |
+
results[key] = agent_response
|
| 324 |
+
output = output.replace("โณ ๋ถ์ ์ค...\n\n", f"{agent_response}\n\n---\n\n")
|
| 325 |
+
yield output
|
| 326 |
+
if len(results) > 1 and "coordinator" not in selected_agents:
|
| 327 |
+
output += f"## {SOMA_AGENTS['coordinator']['name']}\nโณ ์ข
ํฉ ๋ถ์ ์ค...\n\n"
|
| 328 |
+
yield output
|
| 329 |
+
summary_prompt = f"๊ฐ ์ ๋ฌธ๊ฐ ๋ถ์์ ์ข
ํฉํ์ฌ Executive Summary๋ฅผ ์์ฑํ์ธ์:\n" + "\n".join([f"### {SOMA_AGENTS[k]['name']}:\n{v[:1000]}" for k, v in results.items()])
|
| 330 |
+
coord_response = ""
|
| 331 |
+
for chunk in generate_response(summary_prompt, [], SOMA_AGENTS['coordinator']['prompt']):
|
| 332 |
+
coord_response = chunk
|
| 333 |
+
output = output.replace("โณ ์ข
ํฉ ๋ถ์ ์ค...\n\n", f"{coord_response}\n\n")
|
| 334 |
+
yield output
|
| 335 |
+
yield output + "\nโ
**SOMA ๋ถ์ ์๋ฃ**"
|
| 336 |
+
def analyze_document(document_text: str, document_type: str, file_upload: Optional[str] = None) -> Generator:
|
| 337 |
+
if file_upload:
|
| 338 |
+
ext = file_upload.lower().split('.')[-1]
|
| 339 |
+
if ext == 'pdf':
|
| 340 |
+
yield "๐ PDF ํ
์คํธ ์ถ์ถ ์ค..."
|
| 341 |
+
extracted = extract_text_from_pdf(file_upload)
|
| 342 |
+
if extracted.startswith("โ") or extracted.startswith("โ ๏ธ"):
|
| 343 |
+
yield extracted
|
| 344 |
+
return
|
| 345 |
+
document_text = extracted
|
| 346 |
+
yield f"๐ PDF ์ถ์ถ ์๋ฃ ({len(extracted):,}์)\n\n๋ถ์ ์ค..."
|
| 347 |
+
elif ext in ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp']:
|
| 348 |
+
yield f"๐ผ๏ธ ์ด๋ฏธ์ง OCR ์ฒ๋ฆฌ ์ค... (Fireworks Vision AI)"
|
| 349 |
+
extracted = extract_text_from_image_fireworks(file_upload)
|
| 350 |
+
if extracted.startswith("โ"):
|
| 351 |
+
yield extracted
|
| 352 |
+
return
|
| 353 |
+
document_text = extracted
|
| 354 |
+
yield f"๐ผ๏ธ OCR ์๋ฃ ({len(extracted):,}์)\n\n**์ถ์ถ๋ ํ
์ค๏ฟฝ๏ฟฝ๏ฟฝ:**\n```\n{extracted[:2000]}{'...' if len(extracted) > 2000 else ''}\n```\n\n๋ถ์ ์ค..."
|
| 355 |
+
else:
|
| 356 |
+
yield f"โ ์ง์ํ์ง ์๋ ํ์: .{ext}"
|
| 357 |
+
return
|
| 358 |
+
if not document_text or not document_text.strip():
|
| 359 |
+
yield "๐ ๋ฌธ์ ๋ด์ฉ์ ์
๋ ฅํ๊ฑฐ๋ ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์."
|
| 360 |
+
return
|
| 361 |
+
prompt = f"""๋ค์ {document_type} ๋ฌธ์๋ฅผ ๋ถ์ํด์ฃผ์ธ์:
|
| 362 |
+
---
|
| 363 |
+
{document_text[:8000]}
|
| 364 |
+
---
|
| 365 |
+
๋ค์ ํ์์ผ๋ก ๋ถ์:
|
| 366 |
+
## ๐ ๋ฌธ์ ์์ฝ (3์ค)
|
| 367 |
+
## ๐ ํต์ฌ ์ ๋ณด
|
| 368 |
+
## โ ๏ธ ๋ฆฌ์คํฌ ํฌ์ธํธ
|
| 369 |
+
## ๐ก ์ต์ ํ ์ ์
|
| 370 |
+
## ๐ ์ก์
์์ดํ
"""
|
| 371 |
+
full_output = ""
|
| 372 |
+
for chunk in generate_response(prompt, [], DOCUMENT_ANALYSIS_PROMPT):
|
| 373 |
+
full_output = chunk
|
| 374 |
+
yield full_output
|
| 375 |
+
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n"
|
| 376 |
+
yield full_output
|
| 377 |
+
mini_agents = [("legal_advisor", "โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ"), ("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ")]
|
| 378 |
+
for agent_key, agent_label in mini_agents:
|
| 379 |
+
agent = SOMA_AGENTS.get(agent_key)
|
| 380 |
+
if not agent: continue
|
| 381 |
+
full_output += f"### {agent_label}\n"
|
| 382 |
+
yield full_output + "๋ถ์ ์ค...\n"
|
| 383 |
+
mini_prompt = f"{agent['prompt']}\n\n๋ฌธ์ ๋ด์ฉ:\n{document_text[:3000]}\n\nํต์ฌ ํฌ์ธํธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ๋ถ์ํด์ฃผ์ธ์. ๊ฐ ํฌ์ธํธ๋ 1-2๋ฌธ์ฅ์ผ๋ก."
|
| 384 |
+
agent_response = ""
|
| 385 |
+
for chunk in generate_response(mini_prompt, [], agent['prompt']):
|
| 386 |
+
agent_response = chunk
|
| 387 |
+
full_output += f"{agent_response}\n\n"
|
| 388 |
+
yield full_output
|
| 389 |
+
def analyze_cost(building_name, monthly_rent, maintenance, utility, personnel, repair, other, vacancy_rate, additional_info) -> Generator:
|
| 390 |
+
total = maintenance + utility + personnel + repair + other
|
| 391 |
+
noi = monthly_rent * (1 - vacancy_rate/100) - total
|
| 392 |
+
cost_data = f"""๊ฑด๋ฌผ๋ช
: {building_name}
|
| 393 |
+
์ ์๋์์
: {monthly_rent:,.0f}์ | ๊ณต์ค๋ฅ : {vacancy_rate}%
|
| 394 |
+
์ด์๋น์ฉ ๋ด์ญ:
|
| 395 |
+
- ๊ด๋ฆฌ๋น: {maintenance:,.0f}์ ({maintenance/total*100:.1f}%)
|
| 396 |
+
- ์ ํธ๋ฆฌํฐ: {utility:,.0f}์ ({utility/total*100:.1f}%)
|
| 397 |
+
- ์ธ๊ฑด๋น: {personnel:,.0f}์ ({personnel/total*100:.1f}%)
|
| 398 |
+
- ์์ ์ ์ง๋น: {repair:,.0f}์ ({repair/total*100:.1f}%)
|
| 399 |
+
- ๊ธฐํ: {other:,.0f}์ ({other/total*100:.1f}%)
|
| 400 |
+
- ์ด ์ด์๋น์ฉ: {total:,.0f}์
|
| 401 |
+
- ์์ด์์์ต(NOI): {noi:,.0f}์
|
| 402 |
+
์ถ๊ฐ์ ๋ณด: {additional_info or '์์'}"""
|
| 403 |
+
prompt = f"""๊ฑด๋ฌผ ์ด์๋น์ฉ์ ๋ถ์ํด์ฃผ์ธ์:
|
| 404 |
+
{cost_data}
|
| 405 |
+
๋ถ์ ํ์:
|
| 406 |
+
## ๐ ๋น์ฉ ๊ตฌ์กฐ ๋ถ์
|
| 407 |
+
## ๐ด ๋์ ํฌ์ธํธ ์๋ณ
|
| 408 |
+
## ๐ฐ ์ ๊ฐ ๊ฐ๋ฅ ํญ๋ชฉ (๊ตฌ์ฒด์ ๊ธ์ก ์ ์)
|
| 409 |
+
## ๐ ROI ๊ธฐ๋ฐ ์ฐ์ ์์
|
| 410 |
+
## ๐ต ์์ ์ ๊ฐ ํจ๊ณผ (์๊ฐ/์ฐ๊ฐ)"""
|
| 411 |
+
full_output = ""
|
| 412 |
+
for chunk in generate_response(prompt, [], COST_ANALYSIS_PROMPT):
|
| 413 |
+
full_output = chunk
|
| 414 |
+
yield full_output
|
| 415 |
+
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n"
|
| 416 |
+
yield full_output
|
| 417 |
+
mini_agents = [("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ"), ("facility_manager", "๐ง ์์ค ๊ด๋ฆฌ์")]
|
| 418 |
+
for agent_key, agent_label in mini_agents:
|
| 419 |
+
agent = SOMA_AGENTS.get(agent_key)
|
| 420 |
+
if not agent: continue
|
| 421 |
+
full_output += f"### {agent_label}\n"
|
| 422 |
+
yield full_output + "๋ถ์ ์ค...\n"
|
| 423 |
+
mini_prompt = f"{agent['prompt']}\n\n๋น์ฉ ๋ฐ์ดํฐ:\n{cost_data}\n\n๋น์ ์ ์ ๋ฌธ ๋ถ์ผ ๊ด์ ์์ ํต์ฌ ์ธ์ฌ์ดํธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ์ ์ํด์ฃผ์ธ์."
|
| 424 |
+
agent_response = ""
|
| 425 |
+
for chunk in generate_response(mini_prompt, [], agent['prompt']):
|
| 426 |
+
agent_response = chunk
|
| 427 |
+
full_output += f"{agent_response}\n\n"
|
| 428 |
+
yield full_output
|
| 429 |
+
def create_seoul_map(selected: str = None) -> str:
|
| 430 |
+
if not FOLIUM_AVAILABLE:
|
| 431 |
+
return "<div style='padding:40px;text-align:center;'><p>folium ์ค์น ํ์</p></div>"
|
| 432 |
+
m = folium.Map(location=[37.5665, 126.9780], zoom_start=11, tiles='cartodbpositron')
|
| 433 |
+
for name, info in SEOUL_DISTRICTS.items():
|
| 434 |
+
color = 'red' if name == selected else 'blue'
|
| 435 |
+
popup = f"<b>{name}</b><br>{info['ํน์ฑ']}<br>์๋๋ฃ: {info['ํ๊ท ์๋๋ฃ']:,}์/ํ"
|
| 436 |
+
folium.Marker([info['lat'], info['lng']], popup=popup, tooltip=name, icon=folium.Icon(color=color, icon='building', prefix='fa')).add_to(m)
|
| 437 |
+
if name == selected:
|
| 438 |
+
folium.Circle([info['lat'], info['lng']], radius=1500, color='red', fill=True, fillOpacity=0.2).add_to(m)
|
| 439 |
+
return m._repr_html_()
|
| 440 |
+
def analyze_location(district: str) -> Generator:
|
| 441 |
+
if district not in SEOUL_DISTRICTS:
|
| 442 |
+
yield "์ง์ญ ์ ๋ณด ์์"
|
| 443 |
+
return
|
| 444 |
+
info = SEOUL_DISTRICTS[district]
|
| 445 |
+
location_data = f"""์ง์ญ: ์์ธ์ {district}
|
| 446 |
+
ํน์ฑ: {info['ํน์ฑ']}
|
| 447 |
+
ํ๊ท ์๋๋ฃ: {info['ํ๊ท ์๋๋ฃ']:,}์/ํ
|
| 448 |
+
์์น: ์๋ {info['lat']}, ๊ฒฝ๋ {info['lng']}"""
|
| 449 |
+
prompt = f"""์์ธ์ {district}์ ์๊ถ ๋ฐ ๋ถ๋์ฐ ์
์ง๋ฅผ ๋ถ์ํด์ฃผ์ธ์.
|
| 450 |
+
{location_data}
|
| 451 |
+
๋ค์ ๊ด์ ์์ ์์ธํ ๋ถ์:
|
| 452 |
+
## ๐ ์๊ถ ํน์ฑ ๋ถ์
|
| 453 |
+
(์ฃผ์ ์
์ข
, ์ ๋์ธ๊ตฌ ํจํด, ์๋น ํน์ฑ)
|
| 454 |
+
## ๐ข ์คํผ์ค/์๊ฐ ์์ฅ ํํฉ
|
| 455 |
+
(์๋๋ฃ ์์ค, ๊ณต์ค๋ฅ ์ถ์ด, ์์-๊ณต๊ธ)
|
| 456 |
+
## ๐ ํฌ์ ๋งค๋ ฅ๋ ํ๊ฐ
|
| 457 |
+
(์์ฐ๊ฐ์น ์์น ๊ฐ๋ฅ์ฑ, ๊ฐ๋ฐ ํธ์ฌ)
|
| 458 |
+
## โ ๏ธ ๋ฆฌ์คํฌ ์์ธ
|
| 459 |
+
## ๐ฏ ์ถ์ฒ ์ ๋ต"""
|
| 460 |
+
full_output = ""
|
| 461 |
+
for chunk in generate_response(prompt, [], SOMA_AGENTS['market_analyst']['prompt']):
|
| 462 |
+
full_output = chunk
|
| 463 |
+
yield full_output
|
| 464 |
+
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n"
|
| 465 |
+
yield full_output
|
| 466 |
+
mini_agents = [("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ"), ("facility_manager", "๐ง ์์ค ๊ด๋ฆฌ์")]
|
| 467 |
+
for agent_key, agent_label in mini_agents:
|
| 468 |
+
agent = SOMA_AGENTS.get(agent_key)
|
| 469 |
+
if not agent: continue
|
| 470 |
+
full_output += f"### {agent_label}\n"
|
| 471 |
+
yield full_output + "๋ถ์ ์ค...\n"
|
| 472 |
+
mini_prompt = f"{agent['prompt']}\n\n์
์ง ์ ๋ณด:\n{location_data}\n\n์ด ์ง์ญ์์ ์์ฐ๊ด๋ฆฌ ์ ๋น์ ์ ์ ๋ฌธ ๋ถ์ผ ๊ด์ ์์ ํต์ฌ ์กฐ์ธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ์ ์ํด์ฃผ์ธ์."
|
| 473 |
+
agent_response = ""
|
| 474 |
+
for chunk in generate_response(mini_prompt, [], agent['prompt']):
|
| 475 |
+
agent_response = chunk
|
| 476 |
+
full_output += f"{agent_response}\n\n"
|
| 477 |
+
yield full_output
|
| 478 |
+
def create_cost_chart(m, u, p, r, o):
|
| 479 |
+
if not PLOTLY_AVAILABLE: return None
|
| 480 |
+
fig = go.Figure(data=[go.Pie(labels=['๊ด๋ฆฌ๋น','์ ํธ๋ฆฌํฐ','์ธ๊ฑด๋น','์์ ๋น','๊ธฐํ'], values=[m,u,p,r,o], hole=0.4, marker_colors=['#3B82F6','#10B981','#F59E0B','#EF4444','#8B5CF6'])])
|
| 481 |
+
fig.update_layout(title='์๊ฐ ์ด์๋น์ฉ', height=350, paper_bgcolor='#ffffff', font=dict(color='#1e293b'))
|
| 482 |
+
return fig
|
| 483 |
+
CSS = """
|
| 484 |
+
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700&display=swap');
|
| 485 |
+
.gradio-container { background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #f1f5f9 100%) !important; font-family: 'Noto Sans KR', sans-serif !important; min-height: 100vh; }
|
| 486 |
+
.gr-button-primary { background: linear-gradient(135deg, #2563eb, #3b82f6) !important; border: none !important; color: white !important; font-weight: 600 !important; box-shadow: 0 4px 14px rgba(37,99,235,0.35) !important; }
|
| 487 |
+
.gr-button-primary:hover { background: linear-gradient(135deg, #1d4ed8, #2563eb) !important; transform: translateY(-1px) !important; box-shadow: 0 6px 20px rgba(37,99,235,0.4) !important; }
|
| 488 |
+
.gr-panel, .block { background: #ffffff !important; border: 1px solid #e2e8f0 !important; border-radius: 16px !important; box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important; }
|
| 489 |
+
textarea, input[type="text"], input[type="number"] { background: #ffffff !important; border: 2px solid #e2e8f0 !important; color: #1e293b !important; border-radius: 10px !important; }
|
| 490 |
+
textarea:focus, input:focus { border-color: #3b82f6 !important; box-shadow: 0 0 0 3px rgba(59,130,246,0.15) !important; }
|
| 491 |
+
label, .gr-input-label { color: #334155 !important; font-weight: 500 !important; }
|
| 492 |
+
.gr-markdown { color: #334155 !important; }
|
| 493 |
+
.gr-markdown h1, .gr-markdown h2, .gr-markdown h3 { color: #1e40af !important; font-weight: 700 !important; }
|
| 494 |
+
.gr-markdown h1 { font-size: 1.8em !important; }
|
| 495 |
+
.gr-markdown h2 { font-size: 1.4em !important; }
|
| 496 |
+
.gr-markdown h3 { font-size: 1.2em !important; }
|
| 497 |
+
.gr-chatbot { background: #ffffff !important; border: 1px solid #e2e8f0 !important; border-radius: 16px !important; }
|
| 498 |
+
.gr-tab-nav { background: #f1f5f9 !important; border-radius: 12px !important; padding: 4px !important; }
|
| 499 |
+
.gr-tab-nav button { color: #64748b !important; font-weight: 500 !important; border-radius: 8px !important; }
|
| 500 |
+
.gr-tab-nav button.selected { background: #ffffff !important; color: #2563eb !important; box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important; }
|
| 501 |
+
.gr-accordion { background: #f8fafc !important; border: 1px solid #e2e8f0 !important; border-radius: 12px !important; }
|
| 502 |
+
.gr-dropdown { background: #ffffff !important; border: 2px solid #e2e8f0 !important; border-radius: 10px !important; }
|
| 503 |
+
.gr-checkbox-group { background: #f8fafc !important; border-radius: 10px !important; padding: 12px !important; }
|
| 504 |
+
::-webkit-scrollbar { width: 8px; height: 8px; }
|
| 505 |
+
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
|
| 506 |
+
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; }
|
| 507 |
+
::-webkit-scrollbar-thumb:hover { background: #64748b; }
|
| 508 |
+
footer { display: none !important; }
|
| 509 |
+
"""
|
| 510 |
+
def create_demo():
|
| 511 |
+
with gr.Blocks(title="TenAI PMAI Pro", css=CSS) as demo:
|
| 512 |
+
gr.HTML("""<div style="text-align:center;padding:35px 20px;background:linear-gradient(135deg,#ffffff,#f8fafc);border-radius:20px;border:1px solid #e2e8f0;margin-bottom:25px;box-shadow:0 8px 30px rgba(0,0,0,0.08);">
|
| 513 |
+
<h1 style="color:#1e40af;font-size:2.6em;margin:0;font-weight:800;">๐ข TenAI PMAI Pro</h1>
|
| 514 |
+
<p style="color:#475569;margin:12px 0 5px 0;font-size:1.15em;font-weight:500;">๊ธฐ์
์์ฐ๊ด๋ฆฌ AI ํ๋ซํผ</p>
|
| 515 |
+
<p style="color:#64748b;margin:5px 0 20px 0;font-size:0.95em;">"ํ๋์จ์ด ์๋ ๊ฑด๋ฌผ ์ด์์ฒด์ (OS), TenAI"</p>
|
| 516 |
+
<div style="display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
|
| 517 |
+
<span style="background:linear-gradient(135deg,#2563eb,#3b82f6);padding:10px 22px;border-radius:25px;color:white;font-size:0.9em;font-weight:600;box-shadow:0 4px 12px rgba(37,99,235,0.3);">โก Zero Hardware</span>
|
| 518 |
+
<span style="background:linear-gradient(135deg,#059669,#10b981);padding:10px 22px;border-radius:25px;color:white;font-size:0.9em;font-weight:600;box-shadow:0 4px 12px rgba(16,185,129,0.3);">๐ผ๏ธ Fireworks Vision AI</span>
|
| 519 |
+
<span style="background:linear-gradient(135deg,#7c3aed,#8b5cf6);padding:10px 22px;border-radius:25px;color:white;font-size:0.9em;font-weight:600;box-shadow:0 4px 12px rgba(139,92,246,0.3);">๐ค SOMA Multi-Agent</span>
|
| 520 |
+
</div></div>""")
|
| 521 |
+
with gr.Tabs():
|
| 522 |
+
with gr.Tab("๐ฌ PMAI ์๋ด"):
|
| 523 |
+
gr.Markdown("### ๐ค 24์๊ฐ AI ์์ฐ๊ด๋ฆฌ ๋น์")
|
| 524 |
+
chatbot = gr.Chatbot(height=400)
|
| 525 |
+
with gr.Row():
|
| 526 |
+
msg = gr.Textbox(placeholder="์ง๋ฌธ์ ์
๋ ฅํ์ธ์...", show_label=False, scale=9)
|
| 527 |
+
btn = gr.Button("์ ์ก", variant="primary", scale=1)
|
| 528 |
+
gr.Examples(["๊ณต์ค๋ฅ ์ ๋ฎ์ถ๋ ๋ฐฉ๋ฒ์?", "๊ฑด๋ฌผ ์ ์ง๋ณด์ ๋น์ฉ ์ ๊ฐ ์ ๋ต", "์๋์ฐจ ๊ณ์ฝ ๊ฐฑ์ ์ ์ฃผ์์ "], inputs=msg)
|
| 529 |
+
msg.submit(chat_respond, [msg, chatbot], [chatbot]).then(lambda: "", None, [msg])
|
| 530 |
+
btn.click(chat_respond, [msg, chatbot], [chatbot]).then(lambda: "", None, [msg])
|
| 531 |
+
with gr.Tab("๐ ๋ฌธ์ ๋ถ์"):
|
| 532 |
+
gr.Markdown("### ๐ Vision AI ๋ฌธ์ ๋ถ์\n**PDF** ๋๋ **์ด๋ฏธ์ง**(๊ณ์ฝ์ ์ฌ์ง, ์ค์บ๋ณธ) ์
๋ก๋ ์ ์๋ OCR ์ฒ๋ฆฌ")
|
| 533 |
+
with gr.Row():
|
| 534 |
+
with gr.Column(scale=1):
|
| 535 |
+
doc_type = gr.Dropdown(["์๋์ฐจ๊ณ์ฝ์", "์ ์ง๋ณด์ ๋ฌธ์", "์์ค์ ๊ฒ ๋ณด๊ณ ์", "๊ด๋ฆฌ๋น ๋ด์ญ์", "๊ฑด๋ฌผ ๋๋ฉด", "๊ธฐํ"], value="์๋์ฐจ๊ณ์ฝ์", label="๋ฌธ์ ์ ํ")
|
| 536 |
+
file_upload = gr.File(label="๐ ํ์ผ ์
๋ก๋ (PDF/์ด๋ฏธ์ง)", file_types=[".pdf",".jpg",".jpeg",".png",".gif",".webp"], type="filepath")
|
| 537 |
+
gr.Markdown("<small>โ
์ง์: PDF, JPG, PNG, GIF, WEBP | ๐ผ๏ธ ์ด๋ฏธ์ง๋ Fireworks Vision AI๋ก OCR</small>")
|
| 538 |
+
doc_input = gr.Textbox(lines=6, placeholder="๋๋ ํ
์คํธ ์ง์ ์
๋ ฅ...", label="๋ฌธ์ ๋ด์ฉ")
|
| 539 |
+
analyze_btn = gr.Button("๐ ๋ถ์ ์์", variant="primary", size="lg")
|
| 540 |
+
with gr.Column(scale=1):
|
| 541 |
+
analysis_output = gr.Markdown("### ๐ ๋ถ์ ๊ฒฐ๊ณผ\nํ์ผ ์
๋ก๋ ๋๋ ํ
์คํธ ์
๋ ฅ ํ ๋ถ์ ์์")
|
| 542 |
+
analyze_btn.click(analyze_document, [doc_input, doc_type, file_upload], analysis_output)
|
| 543 |
+
with gr.Tab("๐ฐ ๋น์ฉ ๋ถ์"):
|
| 544 |
+
gr.Markdown("### ๐ ์ด์๋น์ฉ ์ต์ ํ ๋ถ์")
|
| 545 |
+
with gr.Row():
|
| 546 |
+
with gr.Column():
|
| 547 |
+
building = gr.Textbox(label="๊ฑด๋ฌผ๋ช
", value="๊ฐ๋จํ
ํฌํ์")
|
| 548 |
+
rent = gr.Number(label="์ ์๋์์
(์)", value=50000000)
|
| 549 |
+
vacancy = gr.Slider(0, 100, 10, label="๊ณต์ค๋ฅ (%)")
|
| 550 |
+
gr.Markdown("#### ์๊ฐ ์ด์๋น์ฉ")
|
| 551 |
+
m_cost = gr.Number(label="๊ด๋ฆฌ๋น", value=5000000)
|
| 552 |
+
u_cost = gr.Number(label="์ ํธ๋ฆฌํฐ", value=8000000)
|
| 553 |
+
p_cost = gr.Number(label="์ธ๊ฑด๋น", value=12000000)
|
| 554 |
+
r_cost = gr.Number(label="์์ ์ ์ง๋น", value=3000000)
|
| 555 |
+
o_cost = gr.Number(label="๊ธฐํ", value=2000000)
|
| 556 |
+
add_info = gr.Textbox(label="์ถ๊ฐ ์ ๋ณด", lines=2)
|
| 557 |
+
cost_btn = gr.Button("๐ก ๋น์ฉ ๋ถ์", variant="primary")
|
| 558 |
+
with gr.Column():
|
| 559 |
+
cost_chart = gr.Plot()
|
| 560 |
+
cost_output = gr.Markdown("### ๐ ๋ถ์ ๊ฒฐ๊ณผ")
|
| 561 |
+
cost_btn.click(lambda m,u,p,r,o: create_cost_chart(m,u,p,r,o), [m_cost,u_cost,p_cost,r_cost,o_cost], cost_chart)
|
| 562 |
+
cost_btn.click(analyze_cost, [building,rent,m_cost,u_cost,p_cost,r_cost,o_cost,vacancy,add_info], cost_output)
|
| 563 |
+
with gr.Tab("๐บ๏ธ ์
์ง ๋ถ์"):
|
| 564 |
+
gr.Markdown("### ๐ ์์ธ์ ์๊ถ ๋ถ์")
|
| 565 |
+
with gr.Row():
|
| 566 |
+
with gr.Column():
|
| 567 |
+
district = gr.Dropdown(list(SEOUL_DISTRICTS.keys()), value="๊ฐ๋จ๊ตฌ", label="์ง์ญ ์ ํ")
|
| 568 |
+
loc_btn = gr.Button("๐ ์
์ง ๋ถ์", variant="primary")
|
| 569 |
+
with gr.Column():
|
| 570 |
+
map_html = gr.HTML(value=create_seoul_map())
|
| 571 |
+
loc_output = gr.Markdown("### ๋ถ์ ๊ฒฐ๊ณผ")
|
| 572 |
+
district.change(create_seoul_map, [district], [map_html])
|
| 573 |
+
loc_btn.click(analyze_location, [district], loc_output)
|
| 574 |
+
with gr.Tab("๐ค SOMA ํ์
"):
|
| 575 |
+
gr.Markdown("### ๐ค ๋ฉํฐ ์์ด์ ํธ ํ์
๋ถ์\n6๋ช
๏ฟฝ๏ฟฝ AI ์ ๋ฌธ๊ฐ๊ฐ ๋ฌธ์๋ฅผ ๋ค๊ฐ๋๋ก ๋ถ์")
|
| 576 |
+
with gr.Row():
|
| 577 |
+
with gr.Column():
|
| 578 |
+
soma_agents = gr.CheckboxGroup([("๐ ๋ฌธ์๋ถ์๊ฐ","document_analyst"),("๐ฐ ์ฌ๋ฌด์ ๋ฌธ๊ฐ","financial_expert"),("โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ","legal_advisor"),("๐ง ์์ค๊ด๋ฆฌ์","facility_manager"),("๐ ์๊ถ๋ถ์๊ฐ","market_analyst")], value=["document_analyst","financial_expert","legal_advisor"], label="๋ถ์ ํ")
|
| 579 |
+
soma_file = gr.File(label="ํ์ผ ์
๋ก๋", file_types=[".pdf",".jpg",".jpeg",".png"], type="filepath")
|
| 580 |
+
soma_text = gr.Textbox(lines=5, placeholder="๋๋ ํ
์คํธ ์
๋ ฅ...", label="๋ฌธ์ ๋ด์ฉ")
|
| 581 |
+
soma_btn = gr.Button("๐ SOMA ๋ถ์", variant="primary")
|
| 582 |
+
with gr.Column():
|
| 583 |
+
soma_output = gr.Markdown("### SOMA ๋ถ์ ๊ฒฐ๊ณผ")
|
| 584 |
+
def soma_with_file(text, agents, file):
|
| 585 |
+
doc = text or ""
|
| 586 |
+
if file:
|
| 587 |
+
ext = file.lower().split('.')[-1]
|
| 588 |
+
if ext == 'pdf':
|
| 589 |
+
doc = extract_text_from_pdf(file)
|
| 590 |
+
elif ext in ['jpg','jpeg','png','gif','webp']:
|
| 591 |
+
doc = extract_text_from_image_fireworks(file)
|
| 592 |
+
if doc.startswith("โ"):
|
| 593 |
+
yield doc
|
| 594 |
+
return
|
| 595 |
+
if not doc.strip():
|
| 596 |
+
yield "๋ฌธ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
| 597 |
+
return
|
| 598 |
+
yield from run_soma_analysis(doc, agents)
|
| 599 |
+
soma_btn.click(soma_with_file, [soma_text, soma_agents, soma_file], soma_output)
|
| 600 |
+
with gr.Tab("โน๏ธ About"):
|
| 601 |
+
gr.Markdown("""
|
| 602 |
+
## ๐ข TenAI PMAI Pro
|
| 603 |
+
### ๋น์ : "ํ๋์จ์ด ์๋ ๊ฑด๋ฌผ ์ด์์ฒด์ (OS)"
|
| 604 |
+
### ํต์ฌ ๊ธฐ๋ฅ
|
| 605 |
+
| ๊ธฐ๋ฅ | ์ค๋ช
|
|
| 606 |
+
|-----|-----|
|
| 607 |
+
| ๐ผ๏ธ **Fireworks Vision AI** | ์ด๋ฏธ์ง OCR (Qwen3-VL-235B) |
|
| 608 |
+
| ๐ **๋ฌธ์ ๋ถ์** | PDF/์ด๋ฏธ์ง ์๋ ํ
์คํธ ์ถ์ถ ๋ฐ ๋ถ์ |
|
| 609 |
+
| ๐ค **SOMA ๋ฉํฐ์์ด์ ํธ** | 6๋ช
AI ์ ๋ฌธ๊ฐ ํ์
|
|
| 610 |
+
| ๐บ๏ธ **์๊ถ ๋ถ์** | ์์ธ์ 12๊ฐ ๊ตฌ ์
์ง ๋ถ์ |
|
| 611 |
+
### API ์ค์
|
| 612 |
+
```
|
| 613 |
+
FIREWORKS_API_KEY=your_key # Vision AI + LLM
|
| 614 |
+
GROQ_API_KEY=your_key # ๋น ๋ฅธ LLM (์ ํ)
|
| 615 |
+
```
|
| 616 |
+
### Contact
|
| 617 |
+
๐ง ten@tenspace.co.kr | ๐ฑ 010-2710-6246
|
| 618 |
+
""")
|
| 619 |
+
gr.HTML("<div style='text-align:center;padding:20px;margin-top:10px;border-top:1px solid #e2e8f0;background:#f8fafc;border-radius:0 0 16px 16px;'><p style='color:#64748b;font-size:0.9em;margin:0;'>๐ Powered by <strong style='color:#2563eb;'>Ten-AX Engine</strong> | Fireworks Vision AI | SOMA Multi-Agent</p></div>")
|
| 620 |
+
return demo
|
| 621 |
+
if __name__ == "__main__":
|
| 622 |
+
demo = create_demo()
|
| 623 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|