Spaces:
Sleeping
Sleeping
Claude commited on
Fix: Simplify dependencies and add app_gradio.py for HuggingFace Spaces
Browse files- Copy app.py to app_gradio.py as main Space file
- Remove unnecessary dependencies (FastAPI, pydantic, numpy, requests)
- Fix python-multipart version conflict with Gradio
- Update README.md to use app_gradio.py as app_file
- Keep only essential packages: gradio, anthropic, chromadb, sentence-transformers
- README.md +3 -3
- app_gradio.py +346 -0
- requirements.txt +0 -10
README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
---
|
| 2 |
-
title: Financial RAG with
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.0.0
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Financial RAG Chatbot with Metacognition
|
| 3 |
+
emoji: ๐ฆ
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.0.0
|
| 8 |
+
app_file: app_gradio.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
app_gradio.py
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
HuggingFace Spaces์ฉ Gradio ์ฑ
|
| 3 |
+
Financial RAG with Metacognitive Agent
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
from loguru import logger
|
| 10 |
+
import asyncio
|
| 11 |
+
from typing import Dict, Tuple
|
| 12 |
+
|
| 13 |
+
# ๋ก๊น
์ค์
|
| 14 |
+
logger.remove()
|
| 15 |
+
logger.add(
|
| 16 |
+
sys.stdout,
|
| 17 |
+
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <level>{message}</level>",
|
| 18 |
+
level="INFO"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# ํ๋ก์ ํธ ๋ฃจํธ๋ฅผ Python ๊ฒฝ๋ก์ ์ถ๊ฐ
|
| 22 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 23 |
+
|
| 24 |
+
from app.metacognitive_agent import MetaCognitiveAgent
|
| 25 |
+
from app.rag_pipeline import RAGPipeline
|
| 26 |
+
from services.vector_store import VectorStore
|
| 27 |
+
from services.embedder import Embedder
|
| 28 |
+
from utils.config import settings
|
| 29 |
+
|
| 30 |
+
# ๊ธ๋ก๋ฒ ๋ณ์
|
| 31 |
+
rag_pipeline = None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def setup_vector_db():
|
| 35 |
+
"""๋ฒกํฐ DB ์๋ ์ค์ (์์ผ๋ฉด ๋ค์ด๋ก๋ ๋๋ ์์ฑ)"""
|
| 36 |
+
db_path = settings.chroma_persist_directory
|
| 37 |
+
|
| 38 |
+
# ๋ฒกํฐ DB๊ฐ ์ด๋ฏธ ์กด์ฌํ๊ณ ๋น์ด์์ง ์์์ง ํ์ธ
|
| 39 |
+
if os.path.exists(db_path):
|
| 40 |
+
if os.listdir(db_path):
|
| 41 |
+
logger.info("โ
Vector DB already exists. Skipping setup.")
|
| 42 |
+
return True
|
| 43 |
+
|
| 44 |
+
logger.info("๐ฅ Vector DB not found. Setting up...")
|
| 45 |
+
os.makedirs(db_path, exist_ok=True)
|
| 46 |
+
|
| 47 |
+
# ์ต์
1: GitHub Release์์ ๋ค์ด๋ก๋ ์๋
|
| 48 |
+
try:
|
| 49 |
+
import urllib.request
|
| 50 |
+
import tarfile
|
| 51 |
+
|
| 52 |
+
release_url = "https://github.com/csjjin2025/Hallucination_and_Deception_for_financial_RAG/releases/download/v1.0/chroma_db.tar.gz"
|
| 53 |
+
tar_path = "./data/chroma_db.tar.gz"
|
| 54 |
+
|
| 55 |
+
logger.info(f"Attempting to download from {release_url}...")
|
| 56 |
+
urllib.request.urlretrieve(release_url, tar_path)
|
| 57 |
+
|
| 58 |
+
# ํ์ผ ํฌ๊ธฐ ํ์ธ
|
| 59 |
+
file_size = os.path.getsize(tar_path)
|
| 60 |
+
if file_size > 1000:
|
| 61 |
+
logger.info(f"๐ฆ Extracting vector DB ({file_size} bytes)...")
|
| 62 |
+
with tarfile.open(tar_path, 'r:gz') as tar:
|
| 63 |
+
tar.extractall(path='./data/')
|
| 64 |
+
os.remove(tar_path)
|
| 65 |
+
logger.info("โ
Vector DB downloaded and extracted!")
|
| 66 |
+
return True
|
| 67 |
+
else:
|
| 68 |
+
logger.warning(f"Downloaded file too small ({file_size} bytes)")
|
| 69 |
+
os.remove(tar_path)
|
| 70 |
+
except Exception as e:
|
| 71 |
+
logger.warning(f"Failed to download from Release: {e}")
|
| 72 |
+
|
| 73 |
+
# ์ต์
2: ํ
์คํธ DB ์์ฑ
|
| 74 |
+
try:
|
| 75 |
+
logger.info("โ ๏ธ Creating test DB with sample data...")
|
| 76 |
+
import subprocess
|
| 77 |
+
result = subprocess.run(
|
| 78 |
+
["python", "scripts/quick_setup_test_db.py"],
|
| 79 |
+
capture_output=True,
|
| 80 |
+
text=True,
|
| 81 |
+
timeout=300
|
| 82 |
+
)
|
| 83 |
+
if result.returncode == 0:
|
| 84 |
+
logger.info("โ
Test DB created successfully!")
|
| 85 |
+
return True
|
| 86 |
+
else:
|
| 87 |
+
logger.error(f"Test DB creation failed: {result.stderr}")
|
| 88 |
+
return False
|
| 89 |
+
except Exception as e:
|
| 90 |
+
logger.error(f"Failed to create test DB: {e}")
|
| 91 |
+
return False
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def initialize_rag_system():
|
| 95 |
+
"""RAG ์์คํ
์ด๊ธฐํ"""
|
| 96 |
+
global rag_pipeline
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
logger.info("=" * 80)
|
| 100 |
+
logger.info("๐ Financial RAG ์์คํ
์ด๊ธฐํ ์ค...")
|
| 101 |
+
logger.info("=" * 80)
|
| 102 |
+
|
| 103 |
+
# 0. Vector DB ์๋ ์ค์
|
| 104 |
+
logger.info("0๏ธโฃ Vector DB ์ค์ ํ์ธ ์ค...")
|
| 105 |
+
if not setup_vector_db():
|
| 106 |
+
logger.error("โ Vector DB ์ค์ ์คํจ")
|
| 107 |
+
return False
|
| 108 |
+
|
| 109 |
+
# 1. Vector Store ์ด๊ธฐํ
|
| 110 |
+
logger.info("1๏ธโฃ Vector Store ๋ก๋ฉ ์ค...")
|
| 111 |
+
vector_store = VectorStore(
|
| 112 |
+
persist_directory=settings.chroma_persist_directory,
|
| 113 |
+
collection_name=settings.collection_name
|
| 114 |
+
)
|
| 115 |
+
doc_count = vector_store.collection.count()
|
| 116 |
+
logger.info(f"โ
Vector Store ๋ก๋ฉ ์๋ฃ ({doc_count}๊ฐ ๋ฌธ์)")
|
| 117 |
+
|
| 118 |
+
# 2. Embedder ์ด๊ธฐํ
|
| 119 |
+
logger.info("2๏ธโฃ Embedder ์ด๊ธฐํ ์ค...")
|
| 120 |
+
embedder = Embedder(
|
| 121 |
+
model_type=settings.embedding_model,
|
| 122 |
+
model_name=settings.embedding_model_name,
|
| 123 |
+
openai_api_key=settings.openai_api_key,
|
| 124 |
+
cohere_api_key=settings.cohere_api_key
|
| 125 |
+
)
|
| 126 |
+
logger.info(f"โ
Embedder ์ด๊ธฐํ ์๋ฃ ({embedder.get_embedding_dimension()}์ฐจ์)")
|
| 127 |
+
|
| 128 |
+
# 3. Metacognitive Agent ์ด๊ธฐํ
|
| 129 |
+
logger.info("3๏ธโฃ Metacognitive Agent ์ด๊ธฐํ ์ค...")
|
| 130 |
+
agent = MetaCognitiveAgent(api_key=settings.anthropic_api_key)
|
| 131 |
+
logger.info(f"โ
Agent ์ด๊ธฐํ ์๋ฃ ({agent.model})")
|
| 132 |
+
|
| 133 |
+
# 4. RAG Pipeline ์์ฑ
|
| 134 |
+
logger.info("4๏ธโฃ RAG Pipeline ์์ฑ ์ค...")
|
| 135 |
+
rag_pipeline = RAGPipeline(
|
| 136 |
+
vector_store=vector_store,
|
| 137 |
+
embedder=embedder,
|
| 138 |
+
metacognitive_agent=agent
|
| 139 |
+
)
|
| 140 |
+
logger.info("โ
RAG Pipeline ์์ฑ ์๋ฃ")
|
| 141 |
+
|
| 142 |
+
logger.info("=" * 80)
|
| 143 |
+
logger.info("โจ ์์คํ
์ค๋น ์๋ฃ!")
|
| 144 |
+
logger.info(f"๐ Vector DB: {doc_count}๊ฐ ๋ฌธ์")
|
| 145 |
+
logger.info(f"๐ค Model: {agent.model}")
|
| 146 |
+
logger.info("=" * 80)
|
| 147 |
+
|
| 148 |
+
return True
|
| 149 |
+
|
| 150 |
+
except Exception as e:
|
| 151 |
+
logger.error(f"โ ์ด๊ธฐํ ์คํจ: {str(e)}")
|
| 152 |
+
import traceback
|
| 153 |
+
logger.error(traceback.format_exc())
|
| 154 |
+
return False
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def format_sources(sources: list) -> str:
|
| 158 |
+
"""์ถ์ฒ ๋ฌธ์ ํฌ๋งทํ
"""
|
| 159 |
+
if not sources:
|
| 160 |
+
return "์ถ์ฒ ๋ฌธ์๊ฐ ์์ต๋๋ค."
|
| 161 |
+
|
| 162 |
+
formatted = "### ๐ ์ฐธ๊ณ ๋ฌธ์\n\n"
|
| 163 |
+
for idx, source in enumerate(sources[:3], 1): # ์์ 3๊ฐ๋ง ํ์
|
| 164 |
+
similarity = source.get('similarity', 0) * 100
|
| 165 |
+
filename = source.get('source_filename', 'unknown')
|
| 166 |
+
text = source.get('text', '')[:300] # ์ 300์๋ง
|
| 167 |
+
|
| 168 |
+
formatted += f"**{idx}. {filename}** (์ ์ฌ๋: {similarity:.1f}%)\n"
|
| 169 |
+
formatted += f"> {text}...\n\n"
|
| 170 |
+
|
| 171 |
+
return formatted
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def format_metacognition(metacognition: Dict) -> str:
|
| 175 |
+
"""๋ฉํ์ธ์ง ๊ณผ์ ํฌ๋งทํ
"""
|
| 176 |
+
if not metacognition:
|
| 177 |
+
return ""
|
| 178 |
+
|
| 179 |
+
history = metacognition.get('thinking_history', [])
|
| 180 |
+
iterations = metacognition.get('iterations', 0)
|
| 181 |
+
|
| 182 |
+
formatted = f"\n\n### ๐ง ๋ฉํ์ธ์ง ๊ณผ์ ({iterations}ํ ๋ฐ๋ณต)\n\n"
|
| 183 |
+
|
| 184 |
+
for idx, step in enumerate(history, 1):
|
| 185 |
+
stage = step.get('stage', 'unknown')
|
| 186 |
+
content = step.get('content', '')
|
| 187 |
+
|
| 188 |
+
stage_emoji = {
|
| 189 |
+
'planning': '๐',
|
| 190 |
+
'monitoring': '๐๏ธ',
|
| 191 |
+
'evaluation': 'โ
',
|
| 192 |
+
'revision': '๐'
|
| 193 |
+
}.get(stage, '๐ญ')
|
| 194 |
+
|
| 195 |
+
formatted += f"**{stage_emoji} {stage.capitalize()}**\n"
|
| 196 |
+
formatted += f"{content}\n\n"
|
| 197 |
+
|
| 198 |
+
return formatted
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
async def process_query_async(question: str, top_k: int, enable_metacognition: bool) -> Tuple[str, str]:
|
| 202 |
+
"""๋น๋๊ธฐ ์ฟผ๋ฆฌ ์ฒ๋ฆฌ"""
|
| 203 |
+
if not rag_pipeline:
|
| 204 |
+
return "โ ์์คํ
์ด ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.", ""
|
| 205 |
+
|
| 206 |
+
if not question.strip():
|
| 207 |
+
return "โ ์ง๋ฌธ์ ์
๋ ฅํด์ฃผ์ธ์.", ""
|
| 208 |
+
|
| 209 |
+
try:
|
| 210 |
+
logger.info(f"๐ ์ง๋ฌธ: {question}")
|
| 211 |
+
|
| 212 |
+
# RAG ํ์ดํ๋ผ์ธ์ผ๋ก ์ฟผ๋ฆฌ ์ฒ๋ฆฌ
|
| 213 |
+
result = await rag_pipeline.query(
|
| 214 |
+
question=question,
|
| 215 |
+
top_k=top_k,
|
| 216 |
+
enable_metacognition=enable_metacognition
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
# ๋ต๋ณ ํฌ๋งทํ
|
| 220 |
+
answer = result.get('answer', '๋ต๋ณ์ ์์ฑํ ์ ์์ต๋๋ค.')
|
| 221 |
+
sources = result.get('sources', [])
|
| 222 |
+
metacognition = result.get('metacognition', None)
|
| 223 |
+
|
| 224 |
+
# ์ถ๋ ฅ ๊ตฌ์ฑ
|
| 225 |
+
main_output = f"## ๐ฌ ๋ต๋ณ\n\n{answer}\n\n"
|
| 226 |
+
main_output += format_sources(sources)
|
| 227 |
+
|
| 228 |
+
# ๋ฉํ์ธ์ง ๊ณผ์ (๋ณ๋ ํญ)
|
| 229 |
+
meta_output = format_metacognition(metacognition) if metacognition else "๋ฉํ์ธ์ง๊ฐ ๋นํ์ฑํ๋์์ต๋๋ค."
|
| 230 |
+
|
| 231 |
+
logger.info("โ
๋ต๋ณ ์์ฑ ์๋ฃ")
|
| 232 |
+
return main_output, meta_output
|
| 233 |
+
|
| 234 |
+
except Exception as e:
|
| 235 |
+
error_msg = f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 236 |
+
logger.error(error_msg)
|
| 237 |
+
import traceback
|
| 238 |
+
logger.error(traceback.format_exc())
|
| 239 |
+
return error_msg, ""
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def process_query(question: str, top_k: int, enable_metacognition: bool) -> Tuple[str, str]:
|
| 243 |
+
"""Gradio์ฉ ๋๊ธฐ ๋ํผ"""
|
| 244 |
+
loop = asyncio.new_event_loop()
|
| 245 |
+
asyncio.set_event_loop(loop)
|
| 246 |
+
try:
|
| 247 |
+
return loop.run_until_complete(process_query_async(question, top_k, enable_metacognition))
|
| 248 |
+
finally:
|
| 249 |
+
loop.close()
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
| 253 |
+
def create_interface():
|
| 254 |
+
"""Gradio ์ธํฐํ์ด์ค ์์ฑ"""
|
| 255 |
+
|
| 256 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="Financial RAG with Metacognitive Agent") as demo:
|
| 257 |
+
gr.Markdown("""
|
| 258 |
+
# ๐ผ Financial RAG System
|
| 259 |
+
### ๋ฉํ์ธ์ง ์์ด์ ํธ ๊ธฐ๋ฐ ๊ธ์ต/๊ฒฝ์ ์ง์์๋ต ์์คํ
|
| 260 |
+
|
| 261 |
+
์ด ์์คํ
์ ๊ธ์ต/๊ฒฝ์ ๋
ผ๋ฌธ์ ๊ธฐ๋ฐ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํฉ๋๋ค.
|
| 262 |
+
๋ฉํ์ธ์ง ๊ธฐ๋ฅ์ ํ์ฑํํ๋ฉด ๋ ๊น์ด ์๋ ์ฌ๊ณ ๊ณผ์ ์ ๊ฑฐ์ณ ๋ต๋ณ์ ์์ฑํฉ๋๋ค.
|
| 263 |
+
""")
|
| 264 |
+
|
| 265 |
+
with gr.Row():
|
| 266 |
+
with gr.Column(scale=2):
|
| 267 |
+
question_input = gr.Textbox(
|
| 268 |
+
label="๐ฌ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์",
|
| 269 |
+
placeholder="์: ํฌํธํด๋ฆฌ์ค ๋ค๊ฐํ๋ ๋ฌด์์ธ๊ฐ์?",
|
| 270 |
+
lines=3
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
with gr.Row():
|
| 274 |
+
top_k_slider = gr.Slider(
|
| 275 |
+
minimum=1,
|
| 276 |
+
maximum=10,
|
| 277 |
+
value=5,
|
| 278 |
+
step=1,
|
| 279 |
+
label="๐ ๊ฒ์ํ ๋ฌธ์ ๊ฐ์"
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
metacognition_check = gr.Checkbox(
|
| 283 |
+
label="๐ง ๋ฉํ์ธ์ง ํ์ฑํ",
|
| 284 |
+
value=True,
|
| 285 |
+
info="๋ ๊น์ด ์๋ ์ฌ๊ณ ๊ณผ์ (์ฒ๋ฆฌ ์๊ฐ ์ฆ๊ฐ)"
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
submit_btn = gr.Button("๐ ์ง๋ฌธํ๊ธฐ", variant="primary", size="lg")
|
| 289 |
+
|
| 290 |
+
gr.Markdown("""
|
| 291 |
+
### ๐ก ์ฌ์ฉ ํ
|
| 292 |
+
- **๋ฉํ์ธ์ง ํ์ฑํ**: Planning โ Monitoring ๏ฟฝ๏ฟฝ Evaluation โ Revision ๊ณผ์ ์ ๊ฑฐ์ณ ์ ์คํ ๋ต๋ณ ์์ฑ
|
| 293 |
+
- **๋ฉํ์ธ์ง ๋นํ์ฑํ**: ๋น ๋ฅธ ๋ต๋ณ ์์ฑ
|
| 294 |
+
- **๊ฒ์ ๋ฌธ์ ๊ฐ์**: ๋ง์์๋ก ๋ ๋ง์ ์ ๋ณด๋ฅผ ์ฐธ๊ณ ํ์ง๋ง ์ฒ๋ฆฌ ์๊ฐ ์ฆ๊ฐ
|
| 295 |
+
""")
|
| 296 |
+
|
| 297 |
+
with gr.Column(scale=3):
|
| 298 |
+
with gr.Tabs():
|
| 299 |
+
with gr.Tab("๐ ๋ต๋ณ ๋ฐ ์ถ์ฒ"):
|
| 300 |
+
answer_output = gr.Markdown(label="๋ต๋ณ")
|
| 301 |
+
|
| 302 |
+
with gr.Tab("๐ง ๋ฉํ์ธ์ง ๊ณผ์ "):
|
| 303 |
+
metacognition_output = gr.Markdown(label="์ฌ๊ณ ๊ณผ์ ")
|
| 304 |
+
|
| 305 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
| 306 |
+
submit_btn.click(
|
| 307 |
+
fn=process_query,
|
| 308 |
+
inputs=[question_input, top_k_slider, metacognition_check],
|
| 309 |
+
outputs=[answer_output, metacognition_output]
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
# Enter ํค๋ก๋ ์ ์ถ
|
| 313 |
+
question_input.submit(
|
| 314 |
+
fn=process_query,
|
| 315 |
+
inputs=[question_input, top_k_slider, metacognition_check],
|
| 316 |
+
outputs=[answer_output, metacognition_output]
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
gr.Markdown("""
|
| 320 |
+
---
|
| 321 |
+
### ๐ ์์คํ
์ ๋ณด
|
| 322 |
+
- **๋ชจ๋ธ**: Claude 3.5 Sonnet
|
| 323 |
+
- **์๋ฒ ๋ฉ**: sentence-transformers/all-MiniLM-L6-v2
|
| 324 |
+
- **๋ฒกํฐ DB**: ChromaDB
|
| 325 |
+
""")
|
| 326 |
+
|
| 327 |
+
return demo
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
# ๋ฉ์ธ ์คํ
|
| 331 |
+
if __name__ == "__main__":
|
| 332 |
+
# ์์คํ
์ด๊ธฐํ
|
| 333 |
+
logger.info("์์คํ
์ด๊ธฐํ ์์...")
|
| 334 |
+
success = initialize_rag_system()
|
| 335 |
+
|
| 336 |
+
if not success:
|
| 337 |
+
logger.error("์์คํ
์ด๊ธฐํ ์คํจ. ์ข
๋ฃํฉ๋๋ค.")
|
| 338 |
+
sys.exit(1)
|
| 339 |
+
|
| 340 |
+
# Gradio ์ฑ ์คํ
|
| 341 |
+
demo = create_interface()
|
| 342 |
+
demo.launch(
|
| 343 |
+
server_name="0.0.0.0",
|
| 344 |
+
server_port=7860,
|
| 345 |
+
share=False
|
| 346 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
# Gradio (HuggingFace Spaces)
|
| 2 |
gradio>=5.0.0
|
| 3 |
|
| 4 |
-
# FastAPI and Web Server (optional for Render.com)
|
| 5 |
-
fastapi>=0.109.0
|
| 6 |
-
uvicorn[standard]>=0.27.0
|
| 7 |
-
pydantic>=2.5.0
|
| 8 |
-
pydantic-settings>=2.1.0
|
| 9 |
-
|
| 10 |
# Anthropic Claude
|
| 11 |
anthropic>=0.18.0
|
| 12 |
|
|
@@ -17,7 +11,3 @@ sentence-transformers>=2.3.0
|
|
| 17 |
# Utilities
|
| 18 |
python-dotenv>=1.0.0
|
| 19 |
loguru>=0.7.0
|
| 20 |
-
numpy>=1.26.0
|
| 21 |
-
|
| 22 |
-
# Required by ChromaDB
|
| 23 |
-
requests>=2.28.0
|
|
|
|
| 1 |
# Gradio (HuggingFace Spaces)
|
| 2 |
gradio>=5.0.0
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Anthropic Claude
|
| 5 |
anthropic>=0.18.0
|
| 6 |
|
|
|
|
| 11 |
# Utilities
|
| 12 |
python-dotenv>=1.0.0
|
| 13 |
loguru>=0.7.0
|
|
|
|
|
|
|
|
|
|
|
|