File size: 2,705 Bytes
853ebe7
 
c7606b2
915e616
c7606b2
8669429
915e616
2f8968f
 
 
 
8669429
915e616
 
 
 
8669429
915e616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853ebe7
 
 
 
 
 
 
 
 
 
 
2010a15
 
 
 
853ebe7
 
2010a15
853ebe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import yaml
import os

# Ultimate Gradio compatibility fix - dynamically filter kwargs based on component signatures
import gradio as gr
from functools import wraps
import inspect
from huggingface_hub import login
from dotenv import load_dotenv
import os
load_dotenv()

def patch_gradio_component(component_class):
    """Patch a Gradio component to accept only supported kwargs"""
    original_init = component_class.__init__
    
    @wraps(original_init)
    def patched_init(self, *args, **kwargs):
        try:
            sig = inspect.signature(original_init)
            # Filter kwargs to only include parameters the original __init__ accepts
            valid_params = set(sig.parameters.keys())
            filtered_kwargs = {k: v for k, v in kwargs.items() if k in valid_params or 
                              any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values())}
            return original_init(self, *args, **filtered_kwargs)
        except Exception as e:
            # Fallback to original call
            try:
                return original_init(self, *args, **kwargs)
            except TypeError:
                # Last resort - call with no kwargs
                return original_init(self, *args)
    
    component_class.__init__ = patched_init
    return component_class

# Patch all Gradio components
for name in dir(gr):
    try:
        obj = getattr(gr, name)
        if inspect.isclass(obj) and hasattr(obj, '__init__'):
            patch_gradio_component(obj)
    except:
        pass
from smolagents import GradioUI, CodeAgent, InferenceClientModel

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

from tools.web_search import DuckDuckGoSearchTool as WebSearch
from tools.suggest_menu import SimpleTool as SuggestMenu
from tools.final_answer import FinalAnswerTool as FinalAnswer



# Authenticate with Hugging Face using HF_TOKEN from environment
if hf_token := os.getenv('HF_TOKEN'):
    login(hf_token)

model = InferenceClientModel(
model_id='Qwen/Qwen3-Next-80B-A3B-Thinking',
    api_key=os.getenv('HF_TOKEN'),
)

web_search = WebSearch()
suggest_menu = SuggestMenu()
final_answer = FinalAnswer()


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

agent = CodeAgent(
    model=model,
    tools=[web_search, suggest_menu],
    managed_agents=[],
    max_steps=20,
    verbosity_level=1,
    planning_interval=None,
    name=None,
    description=None,
    executor_type='local',
    executor_kwargs={},
    max_print_outputs_length=None,
    prompt_templates=prompt_templates
)
if __name__ == "__main__":
    GradioUI(agent).launch()