|
|
""" |
|
|
TenAI PMAI Pro - ๊ธฐ์
์์ฐ๊ด๋ฆฌ AI ํ๋ซํผ |
|
|
Zero Hardware | Data Monopoly | AI Transformation |
|
|
Fireworks Vision API + Groq LLM |
|
|
""" |
|
|
import gradio as gr |
|
|
import requests |
|
|
import os, json, base64, re |
|
|
from typing import Generator, Optional, List, Dict |
|
|
import pandas as pd |
|
|
import numpy as np |
|
|
try: |
|
|
import fitz |
|
|
PDF_AVAILABLE = True |
|
|
except ImportError: |
|
|
PDF_AVAILABLE = False |
|
|
try: |
|
|
from PIL import Image |
|
|
IMAGE_AVAILABLE = True |
|
|
except ImportError: |
|
|
IMAGE_AVAILABLE = False |
|
|
try: |
|
|
import folium |
|
|
from folium.plugins import HeatMap |
|
|
FOLIUM_AVAILABLE = True |
|
|
except ImportError: |
|
|
FOLIUM_AVAILABLE = False |
|
|
try: |
|
|
import plotly.express as px |
|
|
import plotly.graph_objects as go |
|
|
PLOTLY_AVAILABLE = True |
|
|
except ImportError: |
|
|
PLOTLY_AVAILABLE = False |
|
|
try: |
|
|
from datasets import load_dataset |
|
|
DATASETS_AVAILABLE = True |
|
|
except ImportError: |
|
|
DATASETS_AVAILABLE = False |
|
|
FIREWORKS_API_KEY = os.environ.get("FIREWORKS_API_KEY", "") |
|
|
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "") |
|
|
FIREWORKS_VISION_URL = "https://api.fireworks.ai/inference/v1/chat/completions" |
|
|
FIREWORKS_VISION_MODEL = "accounts/fireworks/models/qwen3-vl-235b-a22b-thinking" |
|
|
DEMO_MODE = not FIREWORKS_API_KEY and not GROQ_API_KEY |
|
|
groq_client = None |
|
|
if GROQ_API_KEY: |
|
|
try: |
|
|
from groq import Groq |
|
|
groq_client = Groq(api_key=GROQ_API_KEY) |
|
|
except: |
|
|
pass |
|
|
PMAI_SYSTEM_PROMPT = """๋น์ ์ TenAI์ PMAI(Property Management AI)์
๋๋ค. ๊ธฐ์
์์ฐ๊ด๋ฆฌ๋ฅผ ์ํ 24์๊ฐ AI ๋น์์
๋๋ค. |
|
|
ํต์ฌ ์ญ๋: Vision AI + RAG + ์ถ๋ก ์์ง ๊ธฐ๋ฐ ๋ฌธ์ ๋ถ์, ๋น์ ํ ๋ฌธ์์ ๋๋ฉด ์ดํด |
|
|
์ ๊ณต ๊ฐ์น: AMC(์์ฐ์ด์ฉ)-์ค์๊ฐ ๊ฐ์นํ๊ฐ, PMC(์๋๊ด๋ฆฌ)-๊ณต์ค๊ด๋ฆฌ ์๋ํ, FMC(์์ค๊ด๋ฆฌ)-์์ค์ ๊ฒ ์๋ํ |
|
|
ํน์ง: Zero Hardware-์ผ์ ์์ด ์ฆ์ ๋์
, ๋ฌธ์ ๊ธฐ๋ฐ ๋ถ์, ๋น์ฉ ์ ๊ฐ & ์์ต ์ฆ๋ |
|
|
ํ๊ตญ์ด๋ก ์น์ ํ๊ณ ์ ๋ฌธ์ ์ผ๋ก ์๋ตํ์ธ์.""" |
|
|
DOCUMENT_ANALYSIS_PROMPT = """๋น์ ์ TenAI์ ๋ฌธ์ ๋ถ์ AI์
๋๋ค. ์
๋ก๋๋ ๋ฌธ์๋ฅผ ๋ถ์ํ์ฌ: |
|
|
1. ํต์ฌ ์ ๋ณด ์ถ์ถ 2. ์ ์ฌ์ ๋ฆฌ์คํฌ ์๋ณ 3. ๋น์ฉ ์ต์ ํ ํฌ์ธํธ ๋์ถ 4. ์คํ ๊ฐ๋ฅํ ์ธ์ฌ์ดํธ ์ ๊ณต""" |
|
|
COST_ANALYSIS_PROMPT = """๋น์ ์ TenAI์ ๋น์ฉ ๋ถ์ AI์
๋๋ค. ์ด์๋น์ฉ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ: |
|
|
1. ๋น์ฉ ๊ตฌ์กฐ ๋ถ์ 2. ๋์ ์ง์ ์๋ณ 3. ์ ๊ฐ ๊ฐ๋ฅ ํญ๋ชฉ ๋์ถ 4. ROI ๊ธฐ๋ฐ ์ฐ์ ์์ ์ ์""" |
|
|
SOMA_AGENTS = { |
|
|
"coordinator": {"name": "๐ฏ ์ข
ํฉ ์ฝ๋๋ค์ดํฐ", "role": "SOMA ํ์ฅ", "prompt": "๋น์ ์ SOMA ํ์ ์ข
ํฉ ์ฝ๋๋ค์ดํฐ์
๋๋ค. ๊ฐ ์ ๋ฌธ๊ฐ์ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์ข
ํฉํ์ฌ Executive Summary๋ฅผ ์์ฑํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}, |
|
|
"document_analyst": {"name": "๐ ๋ฌธ์ ๋ถ์๊ฐ", "role": "๋ฌธ์/๊ณ์ฝ์ ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ๋ฌธ์ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์๋์ฐจ๊ณ์ฝ์, ์ ์ง๋ณด์ ๊ณ์ฝ ๋ฑ์ ์ ๋ฐ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}, |
|
|
"financial_expert": {"name": "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ", "role": "๋น์ฉ/์์ต ๋ถ์", "prompt": "๋น์ ์ SOMA ํ์ ์ฌ๋ฌด ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ๋ฌด์ ์ํฅ์ ๋ถ์ํ๊ณ ๋น์ฉ ์ ๊ฐ ๋ฐฉ์์ ์ ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}, |
|
|
"legal_advisor": {"name": "โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ", "role": "๋ฒ์ ๋ฆฌ์คํฌ ๊ฒํ ", "prompt": "๋น์ ์ SOMA ํ์ ๋ฒ๋ฅ ์๋ฌธ ์ ๋ฌธ๊ฐ์
๋๋ค. ๋ฒ์ ๋ฆฌ์คํฌ, ๋ถ๋ฆฌํ ์กฐํญ์ ์๋ณํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}, |
|
|
"facility_manager": {"name": "๐ง ์์ค ๊ด๋ฆฌ์", "role": "์ด์/์์ค ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ์์ค ๊ด๋ฆฌ ์ ๋ฌธ๊ฐ์
๋๋ค. ์์ค ์ด์ ๊ด์ ์์ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."}, |
|
|
"market_analyst": {"name": "๐ ์๊ถ ๋ถ์๊ฐ", "role": "์
์ง/์๊ถ ์ ๋ฌธ", "prompt": "๋น์ ์ SOMA ํ์ ์๊ถ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
์ง, ์ฃผ๋ณ ์๊ถ, ์ ๋์ธ๊ตฌ๋ฅผ ๋ถ์ํฉ๋๋ค. ํ๊ตญ์ด๋ก ์๋ตํ์ธ์."} |
|
|
} |
|
|
SEOUL_DISTRICTS = { |
|
|
"๊ฐ๋จ๊ตฌ": {"lat": 37.5172, "lng": 127.0473, "ํน์ฑ": "IT/๊ธ์ต ์ค์ฌ, ๊ณ ๊ธ ์คํผ์ค", "ํ๊ท ์๋๋ฃ": 85000}, |
|
|
"์์ด๊ตฌ": {"lat": 37.4837, "lng": 127.0324, "ํน์ฑ": "๋ฒ์กฐํ์ด, ๊ต์ก/๋ฌธํ", "ํ๊ท ์๋๋ฃ": 75000}, |
|
|
"์กํ๊ตฌ": {"lat": 37.5145, "lng": 127.1050, "ํน์ฑ": "์ ์ค ์๊ถ, ์ฃผ๊ฑฐ/์์
๋ณตํฉ", "ํ๊ท ์๋๋ฃ": 65000}, |
|
|
"๋งํฌ๊ตฌ": {"lat": 37.5663, "lng": 126.9014, "ํน์ฑ": "ํ๋/ํฉ์ ์๊ถ, ๋ฌธํ/์์ ", "ํ๊ท ์๋๋ฃ": 55000}, |
|
|
"์๋ฑํฌ๊ตฌ": {"lat": 37.5264, "lng": 126.8963, "ํน์ฑ": "์ฌ์๋ ๊ธ์ต, ํ์์คํ์ด", "ํ๊ท ์๋๋ฃ": 70000}, |
|
|
"์ฉ์ฐ๊ตฌ": {"lat": 37.5324, "lng": 126.9903, "ํน์ฑ": "์ดํ์/ํ๋จ, ์ฌ๊ฐ๋ฐ", "ํ๊ท ์๋๋ฃ": 60000}, |
|
|
"์ฑ๋๊ตฌ": {"lat": 37.5634, "lng": 127.0369, "ํน์ฑ": "์ฑ์๋ ํซํ, ์ง์์ฐ์
", "ํ๊ท ์๋๋ฃ": 55000}, |
|
|
"์ข
๋ก๊ตฌ": {"lat": 37.5735, "lng": 126.9790, "ํน์ฑ": "๋์ฌ CBD, ์ ํต ์๊ถ", "ํ๊ท ์๋๋ฃ": 80000}, |
|
|
"์ค๊ตฌ": {"lat": 37.5641, "lng": 126.9979, "ํน์ฑ": "๋ช
๋/์์ง๋ก, ๊ด๊ด/์์
", "ํ๊ท ์๋๋ฃ": 90000}, |
|
|
"๊ฐ์๊ตฌ": {"lat": 37.5510, "lng": 126.8495, "ํน์ฑ": "๋ง๊ณก์ง๊ตฌ, ์ฐ์
๋จ์ง", "ํ๊ท ์๋๋ฃ": 45000}, |
|
|
"๊ตฌ๋ก๊ตฌ": {"lat": 37.4954, "lng": 126.8874, "ํน์ฑ": "๋์งํธ๋จ์ง, ์ฐ์
", "ํ๊ท ์๋๋ฃ": 40000}, |
|
|
"๊ธ์ฒ๊ตฌ": {"lat": 37.4569, "lng": 126.8956, "ํน์ฑ": "๊ฐ์ฐ๋์งํธ, IT", "ํ๊ท ์๋๋ฃ": 38000}, |
|
|
} |
|
|
MARKET_REGIONS = {'์์ธ': '์์ธ_202506', '๊ฒฝ๊ธฐ': '๊ฒฝ๊ธฐ_202506', '๋ถ์ฐ': '๋ถ์ฐ_202506', '๋๊ตฌ': '๋๊ตฌ_202506', '์ธ์ฒ': '์ธ์ฒ_202506', '๊ด์ฃผ': '๊ด์ฃผ_202506', '๋์ ': '๋์ _202506', '์ธ์ฐ': '์ธ์ฐ_202506', '์ธ์ข
': '์ธ์ข
_202506', '๊ฒฝ๋จ': '๊ฒฝ๋จ_202506', '๊ฒฝ๋ถ': '๊ฒฝ๋ถ_202506', '์ ๋จ': '์ ๋จ_202506', '์ ๋ถ': '์ ๋ถ_202506', '์ถฉ๋จ': '์ถฉ๋จ_202506', '์ถฉ๋ถ': '์ถฉ๋ถ_202506', '๊ฐ์': '๊ฐ์_202506', '์ ์ฃผ': '์ ์ฃผ_202506'} |
|
|
class MarketDataLoader: |
|
|
@staticmethod |
|
|
def load_region_data(region: str, sample_size: int = 20000) -> pd.DataFrame: |
|
|
if not DATASETS_AVAILABLE: |
|
|
return pd.DataFrame() |
|
|
try: |
|
|
file_name = f"์์๊ณต์ธ์์ฅ์งํฅ๊ณต๋จ_์๊ฐ(์๊ถ)์ ๋ณด_{MARKET_REGIONS[region]}.csv" |
|
|
dataset = load_dataset("ginipick/market", data_files=file_name, split="train") |
|
|
df = dataset.to_pandas() |
|
|
return df.sample(n=min(sample_size, len(df)), random_state=42) |
|
|
except: |
|
|
return pd.DataFrame() |
|
|
@staticmethod |
|
|
def load_multiple_regions(regions: List[str], sample_per_region: int = 20000) -> pd.DataFrame: |
|
|
dfs = [MarketDataLoader.load_region_data(r, sample_per_region) for r in regions] |
|
|
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() |
|
|
class MarketAnalyzer: |
|
|
def __init__(self, df: pd.DataFrame): |
|
|
self.df = df |
|
|
self.prepare_data() |
|
|
def prepare_data(self): |
|
|
for col in ['๊ฒฝ๋', '์๋']: |
|
|
if col in self.df.columns: |
|
|
self.df[col] = pd.to_numeric(self.df[col], errors='coerce') |
|
|
self.df = self.df.dropna(subset=['๊ฒฝ๋', '์๋']) |
|
|
if '์ธต์ ๋ณด' in self.df.columns: |
|
|
self.df['์ธต์ ๋ณด_์ซ์'] = self.df['์ธต์ ๋ณด'].apply(self._parse_floor) |
|
|
def _parse_floor(self, floor_str): |
|
|
if pd.isna(floor_str): return None |
|
|
s = str(floor_str) |
|
|
if '์งํ' in s or 'B' in s: |
|
|
m = re.search(r'\d+', s) |
|
|
return -int(m.group()) if m else -1 |
|
|
m = re.search(r'\d+', s) |
|
|
return int(m.group()) if m else None |
|
|
def get_summary(self) -> Dict: |
|
|
return { |
|
|
'์ด์ ํฌ์': len(self.df), |
|
|
'์
์ข
์': self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].nunique() if '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' in self.df.columns else 0, |
|
|
'์์์
์ข
': self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].value_counts().head(5).to_dict() if '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' in self.df.columns else {}, |
|
|
} |
|
|
def create_category_chart(self): |
|
|
if not PLOTLY_AVAILABLE or '์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
' not in self.df.columns: return None |
|
|
top = self.df['์๊ถ์
์ข
์ค๋ถ๋ฅ๋ช
'].value_counts().head(15) |
|
|
fig = px.bar(x=top.values, y=top.index, orientation='h', title='๐ ์์ ์
์ข
TOP 15', color=top.values, color_continuous_scale='blues') |
|
|
fig.update_layout(showlegend=False, height=450) |
|
|
return fig |
|
|
def create_district_chart(self): |
|
|
if not PLOTLY_AVAILABLE or '์๊ตฐ๊ตฌ๋ช
' not in self.df.columns: return None |
|
|
counts = self.df['์๊ตฐ๊ตฌ๋ช
'].value_counts().head(15) |
|
|
fig = px.bar(x=counts.values, y=counts.index, orientation='h', title='๐ ์ง์ญ๋ณ ์ ํฌ ๋ฐ์ง๋', color=counts.values, color_continuous_scale='reds') |
|
|
fig.update_layout(showlegend=False, height=450) |
|
|
return fig |
|
|
def create_heatmap(self, sample_size: int = 2000) -> str: |
|
|
if not FOLIUM_AVAILABLE: return "<p>folium ์ค์น ํ์</p>" |
|
|
df_sample = self.df.sample(n=min(sample_size, len(self.df)), random_state=42) |
|
|
m = folium.Map(location=[df_sample['์๋'].mean(), df_sample['๊ฒฝ๋'].mean()], zoom_start=11, tiles='cartodbpositron') |
|
|
HeatMap([[r['์๋'], r['๊ฒฝ๋']] for _, r in df_sample.iterrows()], radius=15, blur=25).add_to(m) |
|
|
return m._repr_html_() |
|
|
class AppState: |
|
|
def __init__(self): |
|
|
self.analyzer = None |
|
|
app_state = AppState() |
|
|
def encode_image_to_base64(image_path: str) -> str: |
|
|
with open(image_path, "rb") as f: |
|
|
return base64.b64encode(f.read()).decode('utf-8') |
|
|
def get_image_mime_type(file_path: str) -> str: |
|
|
ext = file_path.lower().split('.')[-1] |
|
|
return {'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'png': 'image/png', 'gif': 'image/gif', 'webp': 'image/webp'}.get(ext, 'image/jpeg') |
|
|
def extract_text_from_image_fireworks(image_path: str) -> str: |
|
|
"""Fireworks AI Vision API๋ฅผ ์ฌ์ฉํ ์ด๋ฏธ์ง OCR""" |
|
|
if not FIREWORKS_API_KEY: |
|
|
return """[๋ฐ๋ชจ ๋ชจ๋] ์ด๋ฏธ์ง OCR ๊ฒฐ๊ณผ: |
|
|
--- |
|
|
์๋์ฐจ ๊ณ์ฝ์ |
|
|
์ 1์กฐ (๋ชฉ์ ) ์๋์ธ์ ์๋ ๋ถ๋์ฐ์ ์์ฐจ์ธ์๊ฒ ์๋ํ๋ค. |
|
|
์์ฌ์ง: ์์ธ์ ๊ฐ๋จ๊ตฌ ํ
ํค๋๋ก 123, 5์ธต |
|
|
์๋๋ฉด์ : 330.58ใก (100ํ) |
|
|
์๋๊ธฐ๊ฐ: 2024.01.01 ~ 2026.12.31 (3๋
) |
|
|
๋ณด์ฆ๊ธ: ๊ธ ์ผ์ต์์ (โฉ300,000,000) |
|
|
์์๋๋ฃ: ๊ธ ์ผ์ฒ์ค๋ฐฑ๋ง์์ (โฉ15,000,000) |
|
|
๊ด๋ฆฌ๋น: ํ๋น 25,000์ (์ 250๋ง์) |
|
|
--- |
|
|
โ ๏ธ FIREWORKS_API_KEY ์ค์ ์ ์ค์ OCR ๊ฒฐ๊ณผ ์ ๊ณต""" |
|
|
try: |
|
|
base64_image = encode_image_to_base64(image_path) |
|
|
mime_type = get_image_mime_type(image_path) |
|
|
headers = { |
|
|
"Accept": "application/json", |
|
|
"Content-Type": "application/json", |
|
|
"Authorization": f"Bearer {FIREWORKS_API_KEY}" |
|
|
} |
|
|
payload = { |
|
|
"model": FIREWORKS_VISION_MODEL, |
|
|
"max_tokens": 4096, |
|
|
"temperature": 0.2, |
|
|
"messages": [ |
|
|
{ |
|
|
"role": "user", |
|
|
"content": [ |
|
|
{ |
|
|
"type": "text", |
|
|
"text": """์ด ์ด๋ฏธ์ง๋ ๋ถ๋์ฐ ๊ด๋ จ ๋ฌธ์(๊ณ์ฝ์, ๋๋ฉด, ๊ด๋ฆฌ๋ฌธ์ ๋ฑ)์
๋๋ค. |
|
|
์ด๋ฏธ์ง์ ์๋ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ ํํ๊ฒ ์ถ์ถํด์ฃผ์ธ์. |
|
|
ํ๋ ๋ํ๊ฐ ์๋ค๋ฉด ๊ตฌ์กฐ๋ฅผ ์ ์งํ์ฌ ํ
์คํธ๋ก ๋ณํํด์ฃผ์ธ์. |
|
|
ํ๊ตญ์ด์ ์์ด ๋ชจ๋ ์ ํํ๊ฒ ์ธ์ํด์ฃผ์ธ์. |
|
|
์ถ์ถํ ํ
์คํธ๋ง ์ถ๋ ฅํ๊ณ , ๋ค๋ฅธ ์ค๋ช
์ ํ์ง ๋ง์ธ์.""" |
|
|
}, |
|
|
{ |
|
|
"type": "image_url", |
|
|
"image_url": { |
|
|
"url": f"data:{mime_type};base64,{base64_image}" |
|
|
} |
|
|
} |
|
|
] |
|
|
} |
|
|
] |
|
|
} |
|
|
response = requests.post(FIREWORKS_VISION_URL, headers=headers, json=payload, timeout=60) |
|
|
if response.status_code == 200: |
|
|
result = response.json() |
|
|
content = result.get("choices", [{}])[0].get("message", {}).get("content", "") |
|
|
if content: |
|
|
if "<think>" in content and "</think>" in content: |
|
|
content = re.sub(r'<think>.*?</think>', '', content, flags=re.DOTALL).strip() |
|
|
return content |
|
|
return "โ ๏ธ OCR ๊ฒฐ๊ณผ๊ฐ ๋น์ด์์ต๋๋ค." |
|
|
else: |
|
|
return f"โ API ์ค๋ฅ ({response.status_code}): {response.text[:200]}" |
|
|
except requests.exceptions.Timeout: |
|
|
return "โ API ์๋ต ์๊ฐ ์ด๊ณผ. ๋ค์ ์๋ํด์ฃผ์ธ์." |
|
|
except Exception as e: |
|
|
return f"โ OCR ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}" |
|
|
def extract_text_from_pdf(file_path: str) -> str: |
|
|
if not PDF_AVAILABLE: |
|
|
return "โ PyMuPDF ์ค์น ํ์: pip install pymupdf" |
|
|
try: |
|
|
doc = fitz.open(file_path) |
|
|
texts = [f"--- ํ์ด์ง {i+1} ---\n{page.get_text()}" for i, page in enumerate(doc) if page.get_text().strip()] |
|
|
doc.close() |
|
|
return "\n\n".join(texts) if texts else "โ ๏ธ ํ
์คํธ ์ถ์ถ ์คํจ (์ด๋ฏธ์ง PDF์ผ ์ ์์)" |
|
|
except Exception as e: |
|
|
return f"โ PDF ์ค๋ฅ: {e}" |
|
|
def generate_response_fireworks(message: str, history: list, system_prompt: str) -> Generator: |
|
|
"""Fireworks AI๋ฅผ ์ฌ์ฉํ ํ
์คํธ ์์ฑ (์คํธ๋ฆฌ๋ฐ)""" |
|
|
if not FIREWORKS_API_KEY: |
|
|
demo = f"""## ๐ข PMAI ๋ถ์ ๊ฒฐ๊ณผ |
|
|
**์ง๋ฌธ**: {message} |
|
|
--- |
|
|
### ๐ ๋ถ์ ๋ด์ฉ |
|
|
1. **ํํฉ**: ์
๋ ฅ ๋ด์ฉ ๊ธฐ๋ฐ ์์ฐ๊ด๋ฆฌ ๊ด์ ๋ถ์ ์๋ฃ |
|
|
2. **ํต์ฌ**: Zero Hardware ์ ๊ทผ, ๋ฌธ์ ๊ธฐ๋ฐ ๋น์ฉ ์ ๊ฐ ํฌ์ธํธ ๋์ถ |
|
|
3. **๊ถ์ฅ**: ์ด์๋น์ฉ ๊ตฌ์กฐ ์ฌ๊ฒํ , ์๋์ง ํจ์จํ, ๊ณต์ค๋ฅ ๊ด๋ฆฌ ์ ๋ต |
|
|
> โ ๏ธ ๋ฐ๋ชจ ๋ชจ๋ - FIREWORKS_API_KEY ์ค์ ์ ์์ธ ๋ถ์ ์ ๊ณต""" |
|
|
for i in range(0, len(demo), 20): |
|
|
yield demo[:i+20] |
|
|
return |
|
|
messages = [{"role": "system", "content": system_prompt}] |
|
|
for h in history: |
|
|
if isinstance(h, (list, tuple)) and len(h) >= 2: |
|
|
messages.extend([{"role": "user", "content": str(h[0])}, {"role": "assistant", "content": str(h[1])}]) |
|
|
messages.append({"role": "user", "content": message}) |
|
|
headers = {"Accept": "application/json", "Content-Type": "application/json", "Authorization": f"Bearer {FIREWORKS_API_KEY}"} |
|
|
payload = {"model": "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507", "max_tokens": 4096, "temperature": 0.7, "stream": True, "messages": messages} |
|
|
try: |
|
|
response = requests.post(FIREWORKS_VISION_URL, headers=headers, json=payload, stream=True, timeout=60) |
|
|
if response.status_code == 200: |
|
|
full_response = "" |
|
|
for line in response.iter_lines(): |
|
|
if line: |
|
|
line_text = line.decode('utf-8') |
|
|
if line_text.startswith('data: '): |
|
|
data_str = line_text[6:] |
|
|
if data_str.strip() == '[DONE]': |
|
|
break |
|
|
try: |
|
|
data = json.loads(data_str) |
|
|
content = data.get('choices', [{}])[0].get('delta', {}).get('content', '') |
|
|
if content: |
|
|
full_response += content |
|
|
clean = re.sub(r'<think>.*?</think>', '', full_response, flags=re.DOTALL).strip() |
|
|
yield clean |
|
|
except: |
|
|
continue |
|
|
else: |
|
|
yield f"โ API ์ค๋ฅ: {response.status_code}" |
|
|
except Exception as e: |
|
|
yield f"โ ์ค๋ฅ: {e}" |
|
|
def generate_response(message: str, history: list, system_prompt: str = PMAI_SYSTEM_PROMPT) -> Generator: |
|
|
"""Groq ๋๋ Fireworks๋ฅผ ์ฌ์ฉํ ์๋ต ์์ฑ""" |
|
|
if groq_client: |
|
|
messages = [{"role": "system", "content": system_prompt}] |
|
|
for h in history: |
|
|
if isinstance(h, (list, tuple)) and len(h) >= 2: |
|
|
messages.extend([{"role": "user", "content": str(h[0])}, {"role": "assistant", "content": str(h[1])}]) |
|
|
messages.append({"role": "user", "content": message}) |
|
|
try: |
|
|
completion = groq_client.chat.completions.create(model="llama-3.3-70b-versatile", messages=messages, temperature=0.7, max_tokens=4096, stream=True) |
|
|
response = "" |
|
|
for chunk in completion: |
|
|
if chunk.choices[0].delta.content: |
|
|
response += chunk.choices[0].delta.content |
|
|
yield response |
|
|
return |
|
|
except: |
|
|
pass |
|
|
yield from generate_response_fireworks(message, history, system_prompt) |
|
|
def chat_respond(message: str, history: list): |
|
|
if not message or not message.strip(): |
|
|
yield history or [] |
|
|
return |
|
|
history = history or [] |
|
|
history_api = [] |
|
|
for h in history: |
|
|
if isinstance(h, dict): |
|
|
r, c = h.get("role", ""), h.get("content", "") |
|
|
if r == "user": history_api.append([c, ""]) |
|
|
elif r == "assistant" and history_api: history_api[-1][1] = c |
|
|
new_history = list(history) + [{"role": "user", "content": message}, {"role": "assistant", "content": ""}] |
|
|
for chunk in generate_response(message, history_api, PMAI_SYSTEM_PROMPT): |
|
|
new_history[-1] = {"role": "assistant", "content": chunk} |
|
|
yield new_history |
|
|
def run_soma_analysis(document_text: str, selected_agents: List[str]) -> Generator: |
|
|
if not document_text.strip(): |
|
|
yield "๐ ๋ฌธ์ ๋ด์ฉ์ด ํ์ํฉ๋๋ค." |
|
|
return |
|
|
if not selected_agents: |
|
|
selected_agents = ["document_analyst", "financial_expert", "legal_advisor"] |
|
|
output = "# ๐ค SOMA ๋ฉํฐ ์์ด์ ํธ ํ์
๋ถ์\n\n---\n\n" |
|
|
yield output |
|
|
results = {} |
|
|
for key in selected_agents: |
|
|
agent = SOMA_AGENTS.get(key) |
|
|
if not agent: continue |
|
|
output += f"## {agent['name']}\n**์ญํ **: {agent['role']}\n\nโณ ๋ถ์ ์ค...\n\n" |
|
|
yield output |
|
|
prompt = f"{agent['prompt']}\n\n๋ถ์ํ ๋ฌธ์:\n---\n{document_text[:6000]}\n---\n๊ตฌ์ฒด์ ์ธ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํ์ธ์." |
|
|
agent_response = "" |
|
|
for chunk in generate_response(prompt, [], agent['prompt']): |
|
|
agent_response = chunk |
|
|
results[key] = agent_response |
|
|
output = output.replace("โณ ๋ถ์ ์ค...\n\n", f"{agent_response}\n\n---\n\n") |
|
|
yield output |
|
|
if len(results) > 1 and "coordinator" not in selected_agents: |
|
|
output += f"## {SOMA_AGENTS['coordinator']['name']}\nโณ ์ข
ํฉ ๋ถ์ ์ค...\n\n" |
|
|
yield output |
|
|
summary_prompt = f"๊ฐ ์ ๋ฌธ๊ฐ ๋ถ์์ ์ข
ํฉํ์ฌ Executive Summary๋ฅผ ์์ฑํ์ธ์:\n" + "\n".join([f"### {SOMA_AGENTS[k]['name']}:\n{v[:1000]}" for k, v in results.items()]) |
|
|
coord_response = "" |
|
|
for chunk in generate_response(summary_prompt, [], SOMA_AGENTS['coordinator']['prompt']): |
|
|
coord_response = chunk |
|
|
output = output.replace("โณ ์ข
ํฉ ๋ถ์ ์ค...\n\n", f"{coord_response}\n\n") |
|
|
yield output |
|
|
yield output + "\nโ
**SOMA ๋ถ์ ์๋ฃ**" |
|
|
def analyze_document(document_text: str, document_type: str, file_upload: Optional[str] = None) -> Generator: |
|
|
if file_upload: |
|
|
ext = file_upload.lower().split('.')[-1] |
|
|
if ext == 'pdf': |
|
|
yield "๐ PDF ํ
์คํธ ์ถ์ถ ์ค..." |
|
|
extracted = extract_text_from_pdf(file_upload) |
|
|
if extracted.startswith("โ") or extracted.startswith("โ ๏ธ"): |
|
|
yield extracted |
|
|
return |
|
|
document_text = extracted |
|
|
yield f"๐ PDF ์ถ์ถ ์๋ฃ ({len(extracted):,}์)\n\n๋ถ์ ์ค..." |
|
|
elif ext in ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp']: |
|
|
yield f"๐ผ๏ธ ์ด๋ฏธ์ง OCR ์ฒ๋ฆฌ ์ค... (Fireworks Vision AI)" |
|
|
extracted = extract_text_from_image_fireworks(file_upload) |
|
|
if extracted.startswith("โ"): |
|
|
yield extracted |
|
|
return |
|
|
document_text = extracted |
|
|
yield f"๐ผ๏ธ OCR ์๋ฃ ({len(extracted):,}์)\n\n**์ถ์ถ๋ ํ
์คํธ:**\n```\n{extracted[:2000]}{'...' if len(extracted) > 2000 else ''}\n```\n\n๋ถ์ ์ค..." |
|
|
else: |
|
|
yield f"โ ์ง์ํ์ง ์๋ ํ์: .{ext}" |
|
|
return |
|
|
if not document_text or not document_text.strip(): |
|
|
yield "๐ ๋ฌธ์ ๋ด์ฉ์ ์
๋ ฅํ๊ฑฐ๋ ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์." |
|
|
return |
|
|
prompt = f"""๋ค์ {document_type} ๋ฌธ์๋ฅผ ๋ถ์ํด์ฃผ์ธ์: |
|
|
--- |
|
|
{document_text[:8000]} |
|
|
--- |
|
|
๋ค์ ํ์์ผ๋ก ๋ถ์: |
|
|
## ๐ ๋ฌธ์ ์์ฝ (3์ค) |
|
|
## ๐ ํต์ฌ ์ ๋ณด |
|
|
## โ ๏ธ ๋ฆฌ์คํฌ ํฌ์ธํธ |
|
|
## ๐ก ์ต์ ํ ์ ์ |
|
|
## ๐ ์ก์
์์ดํ
""" |
|
|
full_output = "" |
|
|
for chunk in generate_response(prompt, [], DOCUMENT_ANALYSIS_PROMPT): |
|
|
full_output = chunk |
|
|
yield full_output |
|
|
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n" |
|
|
yield full_output |
|
|
mini_agents = [("legal_advisor", "โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ"), ("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ")] |
|
|
for agent_key, agent_label in mini_agents: |
|
|
agent = SOMA_AGENTS.get(agent_key) |
|
|
if not agent: continue |
|
|
full_output += f"### {agent_label}\n" |
|
|
yield full_output + "๋ถ์ ์ค...\n" |
|
|
mini_prompt = f"{agent['prompt']}\n\n๋ฌธ์ ๋ด์ฉ:\n{document_text[:3000]}\n\nํต์ฌ ํฌ์ธํธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ๋ถ์ํด์ฃผ์ธ์. ๊ฐ ํฌ์ธํธ๋ 1-2๋ฌธ์ฅ์ผ๋ก." |
|
|
agent_response = "" |
|
|
for chunk in generate_response(mini_prompt, [], agent['prompt']): |
|
|
agent_response = chunk |
|
|
full_output += f"{agent_response}\n\n" |
|
|
yield full_output |
|
|
def analyze_cost(building_name, monthly_rent, maintenance, utility, personnel, repair, other, vacancy_rate, additional_info) -> Generator: |
|
|
total = maintenance + utility + personnel + repair + other |
|
|
noi = monthly_rent * (1 - vacancy_rate/100) - total |
|
|
cost_data = f"""๊ฑด๋ฌผ๋ช
: {building_name} |
|
|
์ ์๋์์
: {monthly_rent:,.0f}์ | ๊ณต์ค๋ฅ : {vacancy_rate}% |
|
|
์ด์๋น์ฉ ๋ด์ญ: |
|
|
- ๊ด๋ฆฌ๋น: {maintenance:,.0f}์ ({maintenance/total*100:.1f}%) |
|
|
- ์ ํธ๋ฆฌํฐ: {utility:,.0f}์ ({utility/total*100:.1f}%) |
|
|
- ์ธ๊ฑด๋น: {personnel:,.0f}์ ({personnel/total*100:.1f}%) |
|
|
- ์์ ์ ์ง๋น: {repair:,.0f}์ ({repair/total*100:.1f}%) |
|
|
- ๊ธฐํ: {other:,.0f}์ ({other/total*100:.1f}%) |
|
|
- ์ด ์ด์๋น์ฉ: {total:,.0f}์ |
|
|
- ์์ด์์์ต(NOI): {noi:,.0f}์ |
|
|
์ถ๊ฐ์ ๋ณด: {additional_info or '์์'}""" |
|
|
prompt = f"""๊ฑด๋ฌผ ์ด์๋น์ฉ์ ๋ถ์ํด์ฃผ์ธ์: |
|
|
{cost_data} |
|
|
๋ถ์ ํ์: |
|
|
## ๐ ๋น์ฉ ๊ตฌ์กฐ ๋ถ์ |
|
|
## ๐ด ๋์ ํฌ์ธํธ ์๋ณ |
|
|
## ๐ฐ ์ ๊ฐ ๊ฐ๋ฅ ํญ๋ชฉ (๊ตฌ์ฒด์ ๊ธ์ก ์ ์) |
|
|
## ๐ ROI ๊ธฐ๋ฐ ์ฐ์ ์์ |
|
|
## ๐ต ์์ ์ ๊ฐ ํจ๊ณผ (์๊ฐ/์ฐ๊ฐ)""" |
|
|
full_output = "" |
|
|
for chunk in generate_response(prompt, [], COST_ANALYSIS_PROMPT): |
|
|
full_output = chunk |
|
|
yield full_output |
|
|
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n" |
|
|
yield full_output |
|
|
mini_agents = [("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ"), ("facility_manager", "๐ง ์์ค ๊ด๋ฆฌ์")] |
|
|
for agent_key, agent_label in mini_agents: |
|
|
agent = SOMA_AGENTS.get(agent_key) |
|
|
if not agent: continue |
|
|
full_output += f"### {agent_label}\n" |
|
|
yield full_output + "๋ถ์ ์ค...\n" |
|
|
mini_prompt = f"{agent['prompt']}\n\n๋น์ฉ ๋ฐ์ดํฐ:\n{cost_data}\n\n๋น์ ์ ์ ๋ฌธ ๋ถ์ผ ๊ด์ ์์ ํต์ฌ ์ธ์ฌ์ดํธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ์ ์ํด์ฃผ์ธ์." |
|
|
agent_response = "" |
|
|
for chunk in generate_response(mini_prompt, [], agent['prompt']): |
|
|
agent_response = chunk |
|
|
full_output += f"{agent_response}\n\n" |
|
|
yield full_output |
|
|
def create_seoul_map(selected: str = None) -> str: |
|
|
if not FOLIUM_AVAILABLE: |
|
|
return "<div style='padding:40px;text-align:center;'><p>folium ์ค์น ํ์</p></div>" |
|
|
m = folium.Map(location=[37.5665, 126.9780], zoom_start=11, tiles='cartodbpositron') |
|
|
for name, info in SEOUL_DISTRICTS.items(): |
|
|
color = 'red' if name == selected else 'blue' |
|
|
popup = f"<b>{name}</b><br>{info['ํน์ฑ']}<br>์๋๋ฃ: {info['ํ๊ท ์๋๋ฃ']:,}์/ํ" |
|
|
folium.Marker([info['lat'], info['lng']], popup=popup, tooltip=name, icon=folium.Icon(color=color, icon='building', prefix='fa')).add_to(m) |
|
|
if name == selected: |
|
|
folium.Circle([info['lat'], info['lng']], radius=1500, color='red', fill=True, fillOpacity=0.2).add_to(m) |
|
|
return m._repr_html_() |
|
|
def analyze_location(district: str) -> Generator: |
|
|
if district not in SEOUL_DISTRICTS: |
|
|
yield "์ง์ญ ์ ๋ณด ์์" |
|
|
return |
|
|
info = SEOUL_DISTRICTS[district] |
|
|
location_data = f"""์ง์ญ: ์์ธ์ {district} |
|
|
ํน์ฑ: {info['ํน์ฑ']} |
|
|
ํ๊ท ์๋๋ฃ: {info['ํ๊ท ์๋๋ฃ']:,}์/ํ |
|
|
์์น: ์๋ {info['lat']}, ๊ฒฝ๋ {info['lng']}""" |
|
|
prompt = f"""์์ธ์ {district}์ ์๊ถ ๋ฐ ๋ถ๋์ฐ ์
์ง๋ฅผ ๋ถ์ํด์ฃผ์ธ์. |
|
|
{location_data} |
|
|
๋ค์ ๊ด์ ์์ ์์ธํ ๋ถ์: |
|
|
## ๐ ์๊ถ ํน์ฑ ๋ถ์ |
|
|
(์ฃผ์ ์
์ข
, ์ ๋์ธ๊ตฌ ํจํด, ์๋น ํน์ฑ) |
|
|
## ๐ข ์คํผ์ค/์๊ฐ ์์ฅ ํํฉ |
|
|
(์๋๋ฃ ์์ค, ๊ณต์ค๋ฅ ์ถ์ด, ์์-๊ณต๊ธ) |
|
|
## ๐ ํฌ์ ๋งค๋ ฅ๋ ํ๊ฐ |
|
|
(์์ฐ๊ฐ์น ์์น ๊ฐ๋ฅ์ฑ, ๊ฐ๋ฐ ํธ์ฌ) |
|
|
## โ ๏ธ ๋ฆฌ์คํฌ ์์ธ |
|
|
## ๐ฏ ์ถ์ฒ ์ ๋ต""" |
|
|
full_output = "" |
|
|
for chunk in generate_response(prompt, [], SOMA_AGENTS['market_analyst']['prompt']): |
|
|
full_output = chunk |
|
|
yield full_output |
|
|
full_output += "\n\n---\n\n## ๐ค SOMA ์ ๋ฌธ๊ฐ ์ถ๊ฐ ์ธ์ฌ์ดํธ\n\n" |
|
|
yield full_output |
|
|
mini_agents = [("financial_expert", "๐ฐ ์ฌ๋ฌด ์ ๋ฌธ๊ฐ"), ("facility_manager", "๐ง ์์ค ๊ด๋ฆฌ์")] |
|
|
for agent_key, agent_label in mini_agents: |
|
|
agent = SOMA_AGENTS.get(agent_key) |
|
|
if not agent: continue |
|
|
full_output += f"### {agent_label}\n" |
|
|
yield full_output + "๋ถ์ ์ค...\n" |
|
|
mini_prompt = f"{agent['prompt']}\n\n์
์ง ์ ๋ณด:\n{location_data}\n\n์ด ์ง์ญ์์ ์์ฐ๊ด๋ฆฌ ์ ๋น์ ์ ์ ๋ฌธ ๋ถ์ผ ๊ด์ ์์ ํต์ฌ ์กฐ์ธ 3๊ฐ์ง๋ง ๊ฐ๊ฒฐํ๊ฒ ์ ์ํด์ฃผ์ธ์." |
|
|
agent_response = "" |
|
|
for chunk in generate_response(mini_prompt, [], agent['prompt']): |
|
|
agent_response = chunk |
|
|
full_output += f"{agent_response}\n\n" |
|
|
yield full_output |
|
|
def create_cost_chart(m, u, p, r, o): |
|
|
if not PLOTLY_AVAILABLE: return None |
|
|
fig = go.Figure(data=[go.Pie(labels=['๊ด๋ฆฌ๋น','์ ํธ๋ฆฌํฐ','์ธ๊ฑด๋น','์์ ๋น','๊ธฐํ'], values=[m,u,p,r,o], hole=0.4, marker_colors=['#3B82F6','#10B981','#F59E0B','#EF4444','#8B5CF6'])]) |
|
|
fig.update_layout(title='์๊ฐ ์ด์๋น์ฉ', height=350, paper_bgcolor='#ffffff', font=dict(color='#1e293b')) |
|
|
return fig |
|
|
CSS = """ |
|
|
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700&display=swap'); |
|
|
.gradio-container { background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #f1f5f9 100%) !important; font-family: 'Noto Sans KR', sans-serif !important; min-height: 100vh; } |
|
|
.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; } |
|
|
.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; } |
|
|
.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; } |
|
|
textarea, input[type="text"], input[type="number"] { background: #ffffff !important; border: 2px solid #e2e8f0 !important; color: #1e293b !important; border-radius: 10px !important; } |
|
|
textarea:focus, input:focus { border-color: #3b82f6 !important; box-shadow: 0 0 0 3px rgba(59,130,246,0.15) !important; } |
|
|
label, .gr-input-label { color: #334155 !important; font-weight: 500 !important; } |
|
|
.gr-markdown { color: #334155 !important; } |
|
|
.gr-markdown h1, .gr-markdown h2, .gr-markdown h3 { color: #1e40af !important; font-weight: 700 !important; } |
|
|
.gr-markdown h1 { font-size: 1.8em !important; } |
|
|
.gr-markdown h2 { font-size: 1.4em !important; } |
|
|
.gr-markdown h3 { font-size: 1.2em !important; } |
|
|
.gr-chatbot { background: #ffffff !important; border: 1px solid #e2e8f0 !important; border-radius: 16px !important; } |
|
|
.gr-tab-nav { background: #f1f5f9 !important; border-radius: 12px !important; padding: 4px !important; } |
|
|
.gr-tab-nav button { color: #64748b !important; font-weight: 500 !important; border-radius: 8px !important; } |
|
|
.gr-tab-nav button.selected { background: #ffffff !important; color: #2563eb !important; box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important; } |
|
|
.gr-accordion { background: #f8fafc !important; border: 1px solid #e2e8f0 !important; border-radius: 12px !important; } |
|
|
.gr-dropdown { background: #ffffff !important; border: 2px solid #e2e8f0 !important; border-radius: 10px !important; } |
|
|
.gr-checkbox-group { background: #f8fafc !important; border-radius: 10px !important; padding: 12px !important; } |
|
|
::-webkit-scrollbar { width: 8px; height: 8px; } |
|
|
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; } |
|
|
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; } |
|
|
::-webkit-scrollbar-thumb:hover { background: #64748b; } |
|
|
footer { display: none !important; } |
|
|
""" |
|
|
def create_demo(): |
|
|
with gr.Blocks(title="TenAI PMAI Pro", css=CSS) as demo: |
|
|
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);"> |
|
|
<h1 style="color:#1e40af;font-size:2.6em;margin:0;font-weight:800;">๐ข TenAI PMAI Pro</h1> |
|
|
<p style="color:#475569;margin:12px 0 5px 0;font-size:1.15em;font-weight:500;">๊ธฐ์
์์ฐ๊ด๋ฆฌ AI ํ๋ซํผ</p> |
|
|
<p style="color:#64748b;margin:5px 0 20px 0;font-size:0.95em;">"ํ๋์จ์ด ์๋ ๊ฑด๋ฌผ ์ด์์ฒด์ (OS), TenAI"</p> |
|
|
<div style="display:flex;justify-content:center;gap:12px;flex-wrap:wrap;"> |
|
|
<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> |
|
|
<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> |
|
|
<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> |
|
|
</div></div>""") |
|
|
with gr.Tabs(): |
|
|
with gr.Tab("๐ฌ PMAI ์๋ด"): |
|
|
gr.Markdown("### ๐ค 24์๊ฐ AI ์์ฐ๊ด๋ฆฌ ๋น์") |
|
|
chatbot = gr.Chatbot(height=400) |
|
|
with gr.Row(): |
|
|
msg = gr.Textbox(placeholder="์ง๋ฌธ์ ์
๋ ฅํ์ธ์...", show_label=False, scale=9) |
|
|
btn = gr.Button("์ ์ก", variant="primary", scale=1) |
|
|
gr.Examples(["๊ณต์ค๋ฅ ์ ๋ฎ์ถ๋ ๋ฐฉ๋ฒ์?", "๊ฑด๋ฌผ ์ ์ง๋ณด์ ๋น์ฉ ์ ๊ฐ ์ ๋ต", "์๋์ฐจ ๊ณ์ฝ ๊ฐฑ์ ์ ์ฃผ์์ "], inputs=msg) |
|
|
msg.submit(chat_respond, [msg, chatbot], [chatbot]).then(lambda: "", None, [msg]) |
|
|
btn.click(chat_respond, [msg, chatbot], [chatbot]).then(lambda: "", None, [msg]) |
|
|
with gr.Tab("๐ ๋ฌธ์ ๋ถ์"): |
|
|
gr.Markdown("### ๐ Vision AI ๋ฌธ์ ๋ถ์\n**PDF** ๋๋ **์ด๋ฏธ์ง**(๊ณ์ฝ์ ์ฌ์ง, ์ค์บ๋ณธ) ์
๋ก๋ ์ ์๋ OCR ์ฒ๋ฆฌ") |
|
|
with gr.Row(): |
|
|
with gr.Column(scale=1): |
|
|
doc_type = gr.Dropdown(["์๋์ฐจ๊ณ์ฝ์", "์ ์ง๋ณด์ ๋ฌธ์", "์์ค์ ๊ฒ ๋ณด๊ณ ์", "๊ด๋ฆฌ๋น ๋ด์ญ์", "๊ฑด๋ฌผ ๋๋ฉด", "๊ธฐํ"], value="์๋์ฐจ๊ณ์ฝ์", label="๋ฌธ์ ์ ํ") |
|
|
file_upload = gr.File(label="๐ ํ์ผ ์
๋ก๋ (PDF/์ด๋ฏธ์ง)", file_types=[".pdf",".jpg",".jpeg",".png",".gif",".webp"], type="filepath") |
|
|
gr.Markdown("<small>โ
์ง์: PDF, JPG, PNG, GIF, WEBP | ๐ผ๏ธ ์ด๋ฏธ์ง๋ Fireworks Vision AI๋ก OCR</small>") |
|
|
doc_input = gr.Textbox(lines=6, placeholder="๋๋ ํ
์คํธ ์ง์ ์
๋ ฅ...", label="๋ฌธ์ ๋ด์ฉ") |
|
|
analyze_btn = gr.Button("๐ ๋ถ์ ์์", variant="primary", size="lg") |
|
|
with gr.Column(scale=1): |
|
|
analysis_output = gr.Markdown("### ๐ ๋ถ์ ๊ฒฐ๊ณผ\nํ์ผ ์
๋ก๋ ๋๋ ํ
์คํธ ์
๋ ฅ ํ ๋ถ์ ์์") |
|
|
analyze_btn.click(analyze_document, [doc_input, doc_type, file_upload], analysis_output) |
|
|
with gr.Tab("๐ฐ ๋น์ฉ ๋ถ์"): |
|
|
gr.Markdown("### ๐ ์ด์๋น์ฉ ์ต์ ํ ๋ถ์") |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
building = gr.Textbox(label="๊ฑด๋ฌผ๋ช
", value="๊ฐ๋จํ
ํฌํ์") |
|
|
rent = gr.Number(label="์ ์๋์์
(์)", value=50000000) |
|
|
vacancy = gr.Slider(0, 100, 10, label="๊ณต์ค๋ฅ (%)") |
|
|
gr.Markdown("#### ์๊ฐ ์ด์๋น์ฉ") |
|
|
m_cost = gr.Number(label="๊ด๋ฆฌ๋น", value=5000000) |
|
|
u_cost = gr.Number(label="์ ํธ๋ฆฌํฐ", value=8000000) |
|
|
p_cost = gr.Number(label="์ธ๊ฑด๋น", value=12000000) |
|
|
r_cost = gr.Number(label="์์ ์ ์ง๋น", value=3000000) |
|
|
o_cost = gr.Number(label="๊ธฐํ", value=2000000) |
|
|
add_info = gr.Textbox(label="์ถ๊ฐ ์ ๋ณด", lines=2) |
|
|
cost_btn = gr.Button("๐ก ๋น์ฉ ๋ถ์", variant="primary") |
|
|
with gr.Column(): |
|
|
cost_chart = gr.Plot() |
|
|
cost_output = gr.Markdown("### ๐ ๋ถ์ ๊ฒฐ๊ณผ") |
|
|
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) |
|
|
cost_btn.click(analyze_cost, [building,rent,m_cost,u_cost,p_cost,r_cost,o_cost,vacancy,add_info], cost_output) |
|
|
with gr.Tab("๐บ๏ธ ์
์ง ๋ถ์"): |
|
|
gr.Markdown("### ๐ ์์ธ์ ์๊ถ ๋ถ์") |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
district = gr.Dropdown(list(SEOUL_DISTRICTS.keys()), value="๊ฐ๋จ๊ตฌ", label="์ง์ญ ์ ํ") |
|
|
loc_btn = gr.Button("๐ ์
์ง ๋ถ์", variant="primary") |
|
|
with gr.Column(): |
|
|
map_html = gr.HTML(value=create_seoul_map()) |
|
|
loc_output = gr.Markdown("### ๋ถ์ ๊ฒฐ๊ณผ") |
|
|
district.change(create_seoul_map, [district], [map_html]) |
|
|
loc_btn.click(analyze_location, [district], loc_output) |
|
|
with gr.Tab("๐ค SOMA ํ์
"): |
|
|
gr.Markdown("### ๐ค ๋ฉํฐ ์์ด์ ํธ ํ์
๋ถ์\n6๋ช
์ AI ์ ๋ฌธ๊ฐ๊ฐ ๋ฌธ์๋ฅผ ๋ค๊ฐ๋๋ก ๋ถ์") |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
soma_agents = gr.CheckboxGroup([("๐ ๋ฌธ์๋ถ์๊ฐ","document_analyst"),("๐ฐ ์ฌ๋ฌด์ ๋ฌธ๊ฐ","financial_expert"),("โ๏ธ ๋ฒ๋ฅ ์๋ฌธ๊ฐ","legal_advisor"),("๐ง ์์ค๊ด๋ฆฌ์","facility_manager"),("๐ ์๊ถ๋ถ์๊ฐ","market_analyst")], value=["document_analyst","financial_expert","legal_advisor"], label="๋ถ์ ํ") |
|
|
soma_file = gr.File(label="ํ์ผ ์
๋ก๋", file_types=[".pdf",".jpg",".jpeg",".png"], type="filepath") |
|
|
soma_text = gr.Textbox(lines=5, placeholder="๋๋ ํ
์คํธ ์
๋ ฅ...", label="๋ฌธ์ ๋ด์ฉ") |
|
|
soma_btn = gr.Button("๐ SOMA ๋ถ์", variant="primary") |
|
|
with gr.Column(): |
|
|
soma_output = gr.Markdown("### SOMA ๋ถ์ ๊ฒฐ๊ณผ") |
|
|
def soma_with_file(text, agents, file): |
|
|
doc = text or "" |
|
|
if file: |
|
|
ext = file.lower().split('.')[-1] |
|
|
if ext == 'pdf': |
|
|
doc = extract_text_from_pdf(file) |
|
|
elif ext in ['jpg','jpeg','png','gif','webp']: |
|
|
doc = extract_text_from_image_fireworks(file) |
|
|
if doc.startswith("โ"): |
|
|
yield doc |
|
|
return |
|
|
if not doc.strip(): |
|
|
yield "๋ฌธ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์." |
|
|
return |
|
|
yield from run_soma_analysis(doc, agents) |
|
|
soma_btn.click(soma_with_file, [soma_text, soma_agents, soma_file], soma_output) |
|
|
with gr.Tab("โน๏ธ About"): |
|
|
gr.Markdown(""" |
|
|
## ๐ข TenAI PMAI Pro |
|
|
### ๋น์ : "ํ๋์จ์ด ์๋ ๊ฑด๋ฌผ ์ด์์ฒด์ (OS)" |
|
|
### ํต์ฌ ๊ธฐ๋ฅ |
|
|
| ๊ธฐ๋ฅ | ์ค๋ช
| |
|
|
|-----|-----| |
|
|
| ๐ผ๏ธ **Fireworks Vision AI** | ์ด๋ฏธ์ง OCR (Qwen3-VL-235B) | |
|
|
| ๐ **๋ฌธ์ ๋ถ์** | PDF/์ด๋ฏธ์ง ์๋ ํ
์คํธ ์ถ์ถ ๋ฐ ๋ถ์ | |
|
|
| ๐ค **SOMA ๋ฉํฐ์์ด์ ํธ** | 6๋ช
AI ์ ๋ฌธ๊ฐ ํ์
| |
|
|
| ๐บ๏ธ **์๊ถ ๋ถ์** | ์์ธ์ 12๊ฐ ๊ตฌ ์
์ง ๋ถ์ | |
|
|
### API ์ค์ |
|
|
``` |
|
|
FIREWORKS_API_KEY=your_key # Vision AI + LLM |
|
|
GROQ_API_KEY=your_key # ๋น ๋ฅธ LLM (์ ํ) |
|
|
``` |
|
|
### Contact |
|
|
๐ง ten@tenspace.co.kr | ๐ฑ 010-2710-6246 |
|
|
""") |
|
|
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>") |
|
|
return demo |
|
|
if __name__ == "__main__": |
|
|
demo = create_demo() |
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |