File size: 2,566 Bytes
9c3f5d4
 
7f09a1f
 
 
ddf8215
7f09a1f
 
 
 
ddf8215
 
 
7f09a1f
 
 
aff151b
 
 
ddf8215
aff151b
 
 
 
ddf8215
 
 
 
 
 
 
 
 
 
aff151b
 
 
7f09a1f
 
 
9c3f5d4
 
 
 
 
 
 
 
 
 
 
 
 
7f09a1f
9c3f5d4
7f09a1f
9c3f5d4
 
7f09a1f
9c3f5d4
 
 
 
 
 
 
7f09a1f
9c3f5d4
 
 
7f09a1f
9c3f5d4
 
7f09a1f
 
 
 
 
 
 
9c3f5d4
 
 
 
 
 
 
e7f232c
7f09a1f
 
9c3f5d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import yaml
import os
import gradio as gr

# ---------------------------------------------------
# 🔧 Patch 1: Blocks ignores deprecated kwargs
# ---------------------------------------------------
_old_blocks = gr.Blocks

def PatchedBlocks(*args, **kwargs):
    # Remove smolagents old kwargs
    for k in ["theme", "fill_height"]:
        kwargs.pop(k, None)
    return _old_blocks(*args, **kwargs)

gr.Blocks = PatchedBlocks


# ---------------------------------------------------
# 🔧 Patch 2: Chatbot ignores ALL deprecated kwargs
# ---------------------------------------------------
_old_chatbot = gr.Chatbot

def PatchedChatbot(*args, **kwargs):
    # Allowed kwargs in Gradio 6 Chatbot:
    allowed = {
        "value", "height", "scale", "min_height", "max_height",
        "rtl", "show_copy_button", "avatar_images",
        "layout","render","visible","interactive"
    }

    # Strip unsupported ones
    kwargs = {k: v for k, v in kwargs.items() if k in allowed}

    return _old_chatbot(*args, **kwargs)

gr.Chatbot = PatchedChatbot
# ---------------------------------------------------


from smolagents import GradioUI, CodeAgent, InferenceClientModel

# Get current directory path
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))

from tools.web_search import WebSearchTool as WebSearch
from tools.visit_webpage import VisitWebpageTool as VisitWebpage
from tools.suggest_menu import SimpleTool as SuggestMenu
from tools.catering_service_tool import SimpleTool as CateringServiceTool
from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
from tools.final_answer import FinalAnswerTool as FinalAnswer


# Model
model = InferenceClientModel(
    model_id='Qwen/Qwen3-Next-80B-A3B-Thinking',
)

# Tools
web_search = WebSearch()
visit_webpage = VisitWebpage()
suggest_menu = SuggestMenu()
catering_service_tool = CateringServiceTool()
superhero_party_theme_generator = SuperheroPartyThemeGenerator()
final_answer = FinalAnswer()

# Load Prompts
with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# Agent
agent = CodeAgent(
    model=model,
    tools=[
        web_search,
        visit_webpage,
        suggest_menu,
        catering_service_tool,
        superhero_party_theme_generator,
    ],
    managed_agents=[],
    max_steps=10,
    verbosity_level=2,
    planning_interval=None,
    executor_type='local',
    prompt_templates=prompt_templates
)

# Launch UI
if __name__ == "__main__":
    GradioUI(agent).launch()