Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,19 @@
|
|
| 1 |
"""
|
| 2 |
-
Multi-Agent RAG-Enhanced LLM System
|
| 3 |
๊ฐ๋
์(Supervisor) -> ์ฐฝ์์ฑ ์์ฑ์(Creative) -> ๋นํ์(Critic) -> ๊ฐ๋
์(Final)
|
| 4 |
4๋จ๊ณ ํ์ดํ๋ผ์ธ์ ํตํ ๊ณ ํ์ง ๋ต๋ณ ์์ฑ ์์คํ
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
| 8 |
import json
|
| 9 |
-
import asyncio
|
| 10 |
import time
|
| 11 |
from typing import Optional, List, Dict, Any, Tuple
|
| 12 |
-
from contextlib import asynccontextmanager
|
| 13 |
from datetime import datetime
|
| 14 |
from enum import Enum
|
| 15 |
|
| 16 |
import requests
|
| 17 |
-
import uvicorn
|
| 18 |
-
from fastapi import FastAPI, HTTPException
|
| 19 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 20 |
-
from pydantic import BaseModel, Field
|
| 21 |
import gradio as gr
|
|
|
|
| 22 |
from dotenv import load_dotenv
|
| 23 |
|
| 24 |
# ํ๊ฒฝ๋ณ์ ๋ก๋
|
|
@@ -42,16 +37,6 @@ class Message(BaseModel):
|
|
| 42 |
content: str
|
| 43 |
|
| 44 |
|
| 45 |
-
class ChatRequest(BaseModel):
|
| 46 |
-
messages: List[Message]
|
| 47 |
-
model: str = "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507"
|
| 48 |
-
max_tokens: int = Field(default=4096, ge=1, le=8192)
|
| 49 |
-
temperature: float = Field(default=0.6, ge=0, le=2)
|
| 50 |
-
top_p: float = Field(default=1.0, ge=0, le=1)
|
| 51 |
-
top_k: int = Field(default=40, ge=1, le=100)
|
| 52 |
-
use_search: bool = Field(default=True)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
class AgentResponse(BaseModel):
|
| 56 |
role: AgentRole
|
| 57 |
content: str
|
|
@@ -285,7 +270,7 @@ URL: {result.get('url', 'N/A')}
|
|
| 285 |
|
| 286 |
return "\n".join(formatted)
|
| 287 |
|
| 288 |
-
|
| 289 |
self,
|
| 290 |
query: str,
|
| 291 |
search_results: List[Dict],
|
|
@@ -419,27 +404,39 @@ URL: {result.get('url', 'N/A')}
|
|
| 419 |
# Gradio UI
|
| 420 |
# ============================================================================
|
| 421 |
|
| 422 |
-
def create_gradio_interface(
|
| 423 |
"""Gradio ์ธํฐํ์ด์ค ์์ฑ"""
|
| 424 |
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
message: str,
|
| 427 |
-
history: List[
|
| 428 |
use_search: bool,
|
| 429 |
show_agent_thoughts: bool,
|
| 430 |
search_count: int,
|
| 431 |
temperature: float,
|
| 432 |
max_tokens: int
|
| 433 |
-
):
|
| 434 |
"""์ฟผ๋ฆฌ ์ฒ๋ฆฌ ํจ์"""
|
| 435 |
|
| 436 |
-
if not message:
|
| 437 |
-
return
|
| 438 |
|
| 439 |
try:
|
| 440 |
# ๊ฒ์ ์ํ
|
| 441 |
search_results = []
|
| 442 |
-
if use_search and search_client.api_key:
|
| 443 |
search_results = search_client.search(message, count=search_count)
|
| 444 |
|
| 445 |
# ์ค์
|
|
@@ -449,7 +446,7 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 449 |
}
|
| 450 |
|
| 451 |
# ๋ฉํฐ ์์ด์ ํธ ์ฒ๋ฆฌ
|
| 452 |
-
response =
|
| 453 |
query=message,
|
| 454 |
search_results=search_results,
|
| 455 |
config=config
|
|
@@ -490,15 +487,17 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 490 |
final_answer = response.final_answer
|
| 491 |
final_answer += f"\n\n---\nโฑ๏ธ *์ฒ๋ฆฌ ์๊ฐ: {response.processing_time:.2f}์ด*"
|
| 492 |
|
| 493 |
-
# ํ์คํ ๋ฆฌ ์
๋ฐ์ดํธ
|
| 494 |
-
history.append(
|
|
|
|
| 495 |
|
| 496 |
-
return
|
| 497 |
|
| 498 |
except Exception as e:
|
| 499 |
error_msg = f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 500 |
-
history.append(
|
| 501 |
-
|
|
|
|
| 502 |
|
| 503 |
# Gradio ์ธํฐํ์ด์ค
|
| 504 |
with gr.Blocks(
|
|
@@ -509,9 +508,6 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 509 |
max-width: 1400px !important;
|
| 510 |
margin: auto !important;
|
| 511 |
}
|
| 512 |
-
#chatbot {
|
| 513 |
-
height: 600px !important;
|
| 514 |
-
}
|
| 515 |
"""
|
| 516 |
) as demo:
|
| 517 |
gr.Markdown("""
|
|
@@ -521,13 +517,20 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 521 |
**์ฒ๋ฆฌ ๊ณผ์ :** ๊ฐ๋
์(๊ตฌ์กฐํ) โ ์ฐฝ์์ฑ ์์ฑ์(์ฐฝ์์ ๋ต๋ณ) โ ๋นํ์(๊ฒ์ฆ) โ ์ต์ข
๊ฐ๋
์(์ข
ํฉ)
|
| 522 |
""")
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
with gr.Row():
|
| 525 |
# ๋ฉ์ธ ์ฑํ
์์ญ
|
| 526 |
with gr.Column(scale=3):
|
| 527 |
chatbot = gr.Chatbot(
|
| 528 |
height=500,
|
| 529 |
label="๐ฌ ๋ํ",
|
| 530 |
-
|
| 531 |
)
|
| 532 |
|
| 533 |
msg = gr.Textbox(
|
|
@@ -614,18 +617,26 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 614 |
process_query,
|
| 615 |
inputs=[msg, chatbot, use_search, show_agent_thoughts,
|
| 616 |
search_count, temperature, max_tokens],
|
| 617 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
)
|
| 619 |
|
| 620 |
msg.submit(
|
| 621 |
process_query,
|
| 622 |
inputs=[msg, chatbot, use_search, show_agent_thoughts,
|
| 623 |
search_count, temperature, max_tokens],
|
| 624 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
)
|
| 626 |
|
| 627 |
clear.click(
|
| 628 |
-
lambda: (
|
| 629 |
None,
|
| 630 |
[chatbot, agent_thoughts, search_sources]
|
| 631 |
)
|
|
@@ -633,113 +644,6 @@ def create_gradio_interface(multi_agent_system: MultiAgentSystem, search_client:
|
|
| 633 |
return demo
|
| 634 |
|
| 635 |
|
| 636 |
-
# ============================================================================
|
| 637 |
-
# FastAPI ์ฑ
|
| 638 |
-
# ============================================================================
|
| 639 |
-
|
| 640 |
-
@asynccontextmanager
|
| 641 |
-
async def lifespan(app: FastAPI):
|
| 642 |
-
"""์ฑ ์๋ช
์ฃผ๊ธฐ ๊ด๋ฆฌ"""
|
| 643 |
-
port = int(os.getenv("PORT", 7860))
|
| 644 |
-
print("\n" + "="*60)
|
| 645 |
-
print("๐ Multi-Agent RAG System Starting...")
|
| 646 |
-
print(f"๐ Port: {port}")
|
| 647 |
-
print("="*60)
|
| 648 |
-
yield
|
| 649 |
-
print("\n๐ Shutting down...")
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
app = FastAPI(
|
| 653 |
-
title="Multi-Agent RAG System API",
|
| 654 |
-
description="4-Stage Agent Collaboration System with RAG",
|
| 655 |
-
version="3.0.0",
|
| 656 |
-
lifespan=lifespan
|
| 657 |
-
)
|
| 658 |
-
|
| 659 |
-
# CORS ์ค์
|
| 660 |
-
app.add_middleware(
|
| 661 |
-
CORSMiddleware,
|
| 662 |
-
allow_origins=["*"],
|
| 663 |
-
allow_credentials=True,
|
| 664 |
-
allow_methods=["*"],
|
| 665 |
-
allow_headers=["*"]
|
| 666 |
-
)
|
| 667 |
-
|
| 668 |
-
# ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
| 669 |
-
try:
|
| 670 |
-
llm_client = FireworksClient()
|
| 671 |
-
search_client = BraveSearchClient()
|
| 672 |
-
multi_agent_system = MultiAgentSystem(llm_client, search_client)
|
| 673 |
-
except Exception as e:
|
| 674 |
-
print(f"โ ๏ธ Initialization error: {e}")
|
| 675 |
-
llm_client = None
|
| 676 |
-
search_client = None
|
| 677 |
-
multi_agent_system = None
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
# API ์๋ํฌ์ธํธ
|
| 681 |
-
@app.get("/")
|
| 682 |
-
async def root():
|
| 683 |
-
"""๋ฃจํธ ์๋ํฌ์ธํธ"""
|
| 684 |
-
port = int(os.getenv("PORT", 7860))
|
| 685 |
-
return {
|
| 686 |
-
"name": "Multi-Agent RAG System",
|
| 687 |
-
"version": "3.0.0",
|
| 688 |
-
"status": "running",
|
| 689 |
-
"ui": f"http://localhost:{port}/ui",
|
| 690 |
-
"docs": f"http://localhost:{port}/docs"
|
| 691 |
-
}
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
@app.post("/api/chat")
|
| 695 |
-
async def chat_endpoint(request: ChatRequest):
|
| 696 |
-
"""๋ฉํฐ ์์ด์ ํธ ์ฑํ
API"""
|
| 697 |
-
if not multi_agent_system:
|
| 698 |
-
raise HTTPException(status_code=500, detail="System not initialized")
|
| 699 |
-
|
| 700 |
-
try:
|
| 701 |
-
# ๊ฒ์ ์ํ
|
| 702 |
-
search_results = []
|
| 703 |
-
if request.use_search and search_client.api_key:
|
| 704 |
-
last_message = request.messages[-1].content if request.messages else ""
|
| 705 |
-
search_results = search_client.search(last_message, count=5)
|
| 706 |
-
|
| 707 |
-
# ๋ฉํฐ ์์ด์ ํธ ์ฒ๋ฆฌ
|
| 708 |
-
response = await multi_agent_system.process_with_agents(
|
| 709 |
-
query=request.messages[-1].content,
|
| 710 |
-
search_results=search_results,
|
| 711 |
-
config={
|
| 712 |
-
"temperature": request.temperature,
|
| 713 |
-
"max_tokens": request.max_tokens
|
| 714 |
-
}
|
| 715 |
-
)
|
| 716 |
-
|
| 717 |
-
return response
|
| 718 |
-
|
| 719 |
-
except Exception as e:
|
| 720 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
@app.get("/health")
|
| 724 |
-
async def health_check():
|
| 725 |
-
"""ํฌ์ค ์ฒดํฌ"""
|
| 726 |
-
return {
|
| 727 |
-
"status": "healthy",
|
| 728 |
-
"timestamp": datetime.now().isoformat(),
|
| 729 |
-
"services": {
|
| 730 |
-
"llm": "ready" if llm_client else "not configured",
|
| 731 |
-
"search": "ready" if search_client and search_client.api_key else "not configured",
|
| 732 |
-
"multi_agent": "ready" if multi_agent_system else "not configured"
|
| 733 |
-
}
|
| 734 |
-
}
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
# Gradio ๋ง์ดํธ
|
| 738 |
-
if multi_agent_system:
|
| 739 |
-
gradio_app = create_gradio_interface(multi_agent_system, search_client)
|
| 740 |
-
app = gr.mount_gradio_app(app, gradio_app, path="/ui")
|
| 741 |
-
|
| 742 |
-
|
| 743 |
# ============================================================================
|
| 744 |
# ๋ฉ์ธ ์คํ
|
| 745 |
# ============================================================================
|
|
@@ -757,53 +661,21 @@ if __name__ == "__main__":
|
|
| 757 |
# API ํค ํ์ธ
|
| 758 |
if not os.getenv("FIREWORKS_API_KEY"):
|
| 759 |
print("\nโ ๏ธ FIREWORKS_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 760 |
-
|
| 761 |
-
if key:
|
| 762 |
-
os.environ["FIREWORKS_API_KEY"] = key
|
| 763 |
-
llm_client = FireworksClient(key)
|
| 764 |
|
| 765 |
if not os.getenv("BRAVE_SEARCH_API_KEY"):
|
| 766 |
print("\nโ ๏ธ BRAVE_SEARCH_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 767 |
-
print("
|
| 768 |
-
key = input("Brave Search API Key ์
๋ ฅ (Enter=๊ฑด๋๋ฐ๊ธฐ): ").strip()
|
| 769 |
-
if key:
|
| 770 |
-
os.environ["BRAVE_SEARCH_API_KEY"] = key
|
| 771 |
-
search_client = BraveSearchClient(key)
|
| 772 |
-
|
| 773 |
-
# ์์คํ
์ฌ์ด๊ธฐํ
|
| 774 |
-
if llm_client:
|
| 775 |
-
multi_agent_system = MultiAgentSystem(llm_client, search_client)
|
| 776 |
-
gradio_app = create_gradio_interface(multi_agent_system, search_client)
|
| 777 |
-
app = gr.mount_gradio_app(app, gradio_app, path="/ui")
|
| 778 |
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
print("="*60)
|
| 782 |
|
| 783 |
# Hugging Face Spaces ํ๊ฒฝ ํ์ธ
|
| 784 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
| 785 |
-
port = int(os.getenv("PORT", 7860))
|
| 786 |
|
| 787 |
if is_hf_spaces:
|
| 788 |
print("\n๐ค Hugging Face Spaces์์ ์คํ ์ค...")
|
| 789 |
-
|
| 790 |
else:
|
| 791 |
-
print("\n
|
| 792 |
-
|
| 793 |
-
print(f" ๐ API Docs: http://localhost:{port}/docs")
|
| 794 |
-
print(f" ๐ง Chat API: POST http://localhost:{port}/api/chat")
|
| 795 |
-
|
| 796 |
-
print("\n๐ก Ctrl+C๋ฅผ ๋๋ฌ ์ข
๋ฃ")
|
| 797 |
-
print("="*60 + "\n")
|
| 798 |
-
|
| 799 |
-
# Hugging Face Spaces ํ๊ฒฝ ๊ฐ์ง
|
| 800 |
-
port = int(os.getenv("PORT", 7860))
|
| 801 |
-
host = "0.0.0.0"
|
| 802 |
-
|
| 803 |
-
uvicorn.run(
|
| 804 |
-
app,
|
| 805 |
-
host=host,
|
| 806 |
-
port=port,
|
| 807 |
-
reload=False,
|
| 808 |
-
log_level="info"
|
| 809 |
-
)
|
|
|
|
| 1 |
"""
|
| 2 |
+
Multi-Agent RAG-Enhanced LLM System for Hugging Face Spaces
|
| 3 |
๊ฐ๋
์(Supervisor) -> ์ฐฝ์์ฑ ์์ฑ์(Creative) -> ๋นํ์(Critic) -> ๊ฐ๋
์(Final)
|
| 4 |
4๋จ๊ณ ํ์ดํ๋ผ์ธ์ ํตํ ๊ณ ํ์ง ๋ต๋ณ ์์ฑ ์์คํ
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
| 8 |
import json
|
|
|
|
| 9 |
import time
|
| 10 |
from typing import Optional, List, Dict, Any, Tuple
|
|
|
|
| 11 |
from datetime import datetime
|
| 12 |
from enum import Enum
|
| 13 |
|
| 14 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import gradio as gr
|
| 16 |
+
from pydantic import BaseModel, Field
|
| 17 |
from dotenv import load_dotenv
|
| 18 |
|
| 19 |
# ํ๊ฒฝ๋ณ์ ๋ก๋
|
|
|
|
| 37 |
content: str
|
| 38 |
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
class AgentResponse(BaseModel):
|
| 41 |
role: AgentRole
|
| 42 |
content: str
|
|
|
|
| 270 |
|
| 271 |
return "\n".join(formatted)
|
| 272 |
|
| 273 |
+
def process_with_agents(
|
| 274 |
self,
|
| 275 |
query: str,
|
| 276 |
search_results: List[Dict],
|
|
|
|
| 404 |
# Gradio UI
|
| 405 |
# ============================================================================
|
| 406 |
|
| 407 |
+
def create_gradio_interface():
|
| 408 |
"""Gradio ์ธํฐํ์ด์ค ์์ฑ"""
|
| 409 |
|
| 410 |
+
# ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
| 411 |
+
try:
|
| 412 |
+
llm_client = FireworksClient()
|
| 413 |
+
search_client = BraveSearchClient()
|
| 414 |
+
multi_agent_system = MultiAgentSystem(llm_client, search_client)
|
| 415 |
+
system_ready = True
|
| 416 |
+
except Exception as e:
|
| 417 |
+
print(f"โ ๏ธ System initialization error: {e}")
|
| 418 |
+
multi_agent_system = None
|
| 419 |
+
search_client = None
|
| 420 |
+
system_ready = False
|
| 421 |
+
|
| 422 |
+
def process_query(
|
| 423 |
message: str,
|
| 424 |
+
history: List[Dict],
|
| 425 |
use_search: bool,
|
| 426 |
show_agent_thoughts: bool,
|
| 427 |
search_count: int,
|
| 428 |
temperature: float,
|
| 429 |
max_tokens: int
|
| 430 |
+
) -> Tuple[List[Dict], str, str]:
|
| 431 |
"""์ฟผ๋ฆฌ ์ฒ๋ฆฌ ํจ์"""
|
| 432 |
|
| 433 |
+
if not message or not system_ready:
|
| 434 |
+
return history, "", ""
|
| 435 |
|
| 436 |
try:
|
| 437 |
# ๊ฒ์ ์ํ
|
| 438 |
search_results = []
|
| 439 |
+
if use_search and search_client and search_client.api_key:
|
| 440 |
search_results = search_client.search(message, count=search_count)
|
| 441 |
|
| 442 |
# ์ค์
|
|
|
|
| 446 |
}
|
| 447 |
|
| 448 |
# ๋ฉํฐ ์์ด์ ํธ ์ฒ๋ฆฌ
|
| 449 |
+
response = multi_agent_system.process_with_agents(
|
| 450 |
query=message,
|
| 451 |
search_results=search_results,
|
| 452 |
config=config
|
|
|
|
| 487 |
final_answer = response.final_answer
|
| 488 |
final_answer += f"\n\n---\nโฑ๏ธ *์ฒ๋ฆฌ ์๊ฐ: {response.processing_time:.2f}์ด*"
|
| 489 |
|
| 490 |
+
# ํ์คํ ๋ฆฌ ์
๋ฐ์ดํธ (OpenAI ํ์)
|
| 491 |
+
history.append({"role": "user", "content": message})
|
| 492 |
+
history.append({"role": "assistant", "content": final_answer})
|
| 493 |
|
| 494 |
+
return history, agent_thoughts, search_display
|
| 495 |
|
| 496 |
except Exception as e:
|
| 497 |
error_msg = f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 498 |
+
history.append({"role": "user", "content": message})
|
| 499 |
+
history.append({"role": "assistant", "content": error_msg})
|
| 500 |
+
return history, "", ""
|
| 501 |
|
| 502 |
# Gradio ์ธํฐํ์ด์ค
|
| 503 |
with gr.Blocks(
|
|
|
|
| 508 |
max-width: 1400px !important;
|
| 509 |
margin: auto !important;
|
| 510 |
}
|
|
|
|
|
|
|
|
|
|
| 511 |
"""
|
| 512 |
) as demo:
|
| 513 |
gr.Markdown("""
|
|
|
|
| 517 |
**์ฒ๋ฆฌ ๊ณผ์ :** ๊ฐ๋
์(๊ตฌ์กฐํ) โ ์ฐฝ์์ฑ ์์ฑ์(์ฐฝ์์ ๋ต๋ณ) โ ๋นํ์(๊ฒ์ฆ) โ ์ต์ข
๊ฐ๋
์(์ข
ํฉ)
|
| 518 |
""")
|
| 519 |
|
| 520 |
+
if not system_ready:
|
| 521 |
+
gr.Markdown("""
|
| 522 |
+
โ ๏ธ **์์คํ
์ด๊ธฐํ ์คํจ**: API ํค๋ฅผ ํ์ธํด์ฃผ์ธ์.
|
| 523 |
+
- FIREWORKS_API_KEY ํ์
|
| 524 |
+
- BRAVE_SEARCH_API_KEY (์ ํ์ฌํญ)
|
| 525 |
+
""")
|
| 526 |
+
|
| 527 |
with gr.Row():
|
| 528 |
# ๋ฉ์ธ ์ฑํ
์์ญ
|
| 529 |
with gr.Column(scale=3):
|
| 530 |
chatbot = gr.Chatbot(
|
| 531 |
height=500,
|
| 532 |
label="๐ฌ ๋ํ",
|
| 533 |
+
type="messages" # OpenAI ์คํ์ผ ๋ฉ์์ง ํ์
|
| 534 |
)
|
| 535 |
|
| 536 |
msg = gr.Textbox(
|
|
|
|
| 617 |
process_query,
|
| 618 |
inputs=[msg, chatbot, use_search, show_agent_thoughts,
|
| 619 |
search_count, temperature, max_tokens],
|
| 620 |
+
outputs=[chatbot, agent_thoughts, search_sources]
|
| 621 |
+
).then(
|
| 622 |
+
lambda: "",
|
| 623 |
+
None,
|
| 624 |
+
msg
|
| 625 |
)
|
| 626 |
|
| 627 |
msg.submit(
|
| 628 |
process_query,
|
| 629 |
inputs=[msg, chatbot, use_search, show_agent_thoughts,
|
| 630 |
search_count, temperature, max_tokens],
|
| 631 |
+
outputs=[chatbot, agent_thoughts, search_sources]
|
| 632 |
+
).then(
|
| 633 |
+
lambda: "",
|
| 634 |
+
None,
|
| 635 |
+
msg
|
| 636 |
)
|
| 637 |
|
| 638 |
clear.click(
|
| 639 |
+
lambda: ([], None, None),
|
| 640 |
None,
|
| 641 |
[chatbot, agent_thoughts, search_sources]
|
| 642 |
)
|
|
|
|
| 644 |
return demo
|
| 645 |
|
| 646 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 647 |
# ============================================================================
|
| 648 |
# ๋ฉ์ธ ์คํ
|
| 649 |
# ============================================================================
|
|
|
|
| 661 |
# API ํค ํ์ธ
|
| 662 |
if not os.getenv("FIREWORKS_API_KEY"):
|
| 663 |
print("\nโ ๏ธ FIREWORKS_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 664 |
+
print("Hugging Face Spaces Settings์์ ์ค์ ํด์ฃผ์ธ์.")
|
|
|
|
|
|
|
|
|
|
| 665 |
|
| 666 |
if not os.getenv("BRAVE_SEARCH_API_KEY"):
|
| 667 |
print("\nโ ๏ธ BRAVE_SEARCH_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 668 |
+
print("๊ฒ์ ๊ธฐ๋ฅ์ด ๋นํ์ฑํ๋ฉ๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
|
| 670 |
+
# Gradio ์ฑ ์คํ
|
| 671 |
+
demo = create_gradio_interface()
|
|
|
|
| 672 |
|
| 673 |
# Hugging Face Spaces ํ๊ฒฝ ํ์ธ
|
| 674 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
|
|
|
| 675 |
|
| 676 |
if is_hf_spaces:
|
| 677 |
print("\n๐ค Hugging Face Spaces์์ ์คํ ์ค...")
|
| 678 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 679 |
else:
|
| 680 |
+
print("\n๐ป ๋ก์ปฌ ํ๊ฒฝ์์ ์คํ ์ค...")
|
| 681 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|