Spaces:
Sleeping
Sleeping
Eurico149
commited on
Commit
·
7de7078
1
Parent(s):
bb8cd70
feat: Initial functional agent with base tools
Browse files- .gitignore +2 -1
- app.py +45 -16
- requirements.txt +39 -25
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
/.idea
|
|
|
|
|
|
| 1 |
+
/.idea
|
| 2 |
+
.venv/
|
app.py
CHANGED
|
@@ -1,29 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
agent = CodeAgent(
|
| 6 |
tools=[],
|
| 7 |
-
model=
|
| 8 |
-
max_steps=
|
| 9 |
-
verbosity_level=2
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
-
with gr.Blocks() as demo:
|
| 24 |
-
with gr.Sidebar():
|
| 25 |
-
gr.LoginButton()
|
| 26 |
-
chatbot.render()
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
demo.launch()
|
|
|
|
| 1 |
+
from dataclasses import asdict
|
| 2 |
+
from smolagents import CodeAgent, TransformersModel, InferenceClientModel, stream_to_gradio
|
| 3 |
+
import torch
|
| 4 |
import gradio as gr
|
| 5 |
+
from transformers import BitsAndBytesConfig
|
| 6 |
|
| 7 |
|
| 8 |
+
model_path = "Qwen/Qwen3-4B-Instruct-2507"
|
| 9 |
+
AGENT_SYSTEM_PROMPT = "You are a friendly and helpful Chatbot"
|
| 10 |
+
|
| 11 |
+
quantization = BitsAndBytesConfig(load_in_8bit=True)
|
| 12 |
+
|
| 13 |
+
if torch.cuda.is_available():
|
| 14 |
+
print("\nRunning on Local GPU\n")
|
| 15 |
+
model = TransformersModel(
|
| 16 |
+
model_id=model_path,
|
| 17 |
+
max_new_tokens=1024,
|
| 18 |
+
model_kwargs={
|
| 19 |
+
"quantization_config": quantization
|
| 20 |
+
})
|
| 21 |
+
else:
|
| 22 |
+
print("\nRunning on Hugging Face Ecosystem\n")
|
| 23 |
+
model = InferenceClientModel(
|
| 24 |
+
model_id=model_path,
|
| 25 |
+
model_kwargs={
|
| 26 |
+
"quantization_config": quantization
|
| 27 |
+
}
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
agent = CodeAgent(
|
| 31 |
tools=[],
|
| 32 |
+
model=model,
|
| 33 |
+
max_steps=6,
|
| 34 |
+
verbosity_level=2,
|
| 35 |
+
add_base_tools=True
|
| 36 |
)
|
| 37 |
|
| 38 |
+
def interact_with_agent(prompt, history):
|
| 39 |
+
messages = []
|
| 40 |
+
yield messages
|
| 41 |
+
for msg in stream_to_gradio(agent, prompt):
|
| 42 |
+
messages.append(asdict(msg))
|
| 43 |
+
yield messages
|
| 44 |
+
yield messages
|
| 45 |
|
| 46 |
+
demo = gr.ChatInterface(
|
| 47 |
+
interact_with_agent,
|
| 48 |
+
chatbot=gr.Chatbot(
|
| 49 |
+
label="CodeAgent",
|
| 50 |
+
type="messages",
|
| 51 |
+
),
|
| 52 |
+
textbox=gr.Textbox(placeholder="Ask something..."),
|
| 53 |
+
title="smolagents-poc - Qwen3-4B"
|
| 54 |
)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,41 +1,50 @@
|
|
| 1 |
aiofiles==24.1.0
|
| 2 |
annotated-types==0.7.0
|
| 3 |
-
anyio==4.
|
| 4 |
-
beautifulsoup4==4.13.5
|
| 5 |
Brotli==1.1.0
|
| 6 |
-
certifi==2025.
|
| 7 |
charset-normalizer==3.4.3
|
| 8 |
click==8.3.0
|
| 9 |
-
|
| 10 |
-
fastapi==0.
|
| 11 |
ffmpy==0.6.1
|
| 12 |
filelock==3.19.1
|
| 13 |
fsspec==2025.9.0
|
| 14 |
-
gradio==5.
|
| 15 |
-
gradio_client==1.13.
|
| 16 |
groovy==0.1.2
|
| 17 |
h11==0.16.0
|
| 18 |
-
h2==4.3.0
|
| 19 |
hf-xet==1.1.10
|
| 20 |
-
hpack==4.1.0
|
| 21 |
httpcore==1.0.9
|
| 22 |
httpx==0.28.1
|
| 23 |
-
huggingface-hub==0.35.
|
| 24 |
-
hyperframe==6.1.0
|
| 25 |
idna==3.10
|
| 26 |
Jinja2==3.1.6
|
| 27 |
-
lxml==6.0.1
|
| 28 |
markdown-it-py==4.0.0
|
| 29 |
-
|
| 30 |
-
MarkupSafe==3.0.2
|
| 31 |
mdurl==0.1.2
|
|
|
|
|
|
|
| 32 |
numpy==2.2.6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
orjson==3.11.3
|
| 34 |
packaging==25.0
|
| 35 |
-
pandas==2.3.
|
| 36 |
pillow==11.3.0
|
| 37 |
-
|
| 38 |
-
pydantic==2.11.9
|
| 39 |
pydantic_core==2.33.2
|
| 40 |
pydub==0.25.1
|
| 41 |
Pygments==2.19.2
|
|
@@ -43,25 +52,30 @@ python-dateutil==2.9.0.post0
|
|
| 43 |
python-dotenv==1.1.1
|
| 44 |
python-multipart==0.0.20
|
| 45 |
pytz==2025.2
|
| 46 |
-
PyYAML==6.0.
|
|
|
|
| 47 |
requests==2.32.5
|
| 48 |
rich==14.1.0
|
| 49 |
-
ruff==0.
|
| 50 |
safehttpx==0.1.6
|
|
|
|
| 51 |
semantic-version==2.10.0
|
| 52 |
shellingham==1.5.4
|
| 53 |
six==1.17.0
|
| 54 |
-
smolagents==1.
|
| 55 |
sniffio==1.3.1
|
| 56 |
-
socksio==1.0.0
|
| 57 |
-
soupsieve==2.8
|
| 58 |
starlette==0.48.0
|
|
|
|
|
|
|
| 59 |
tomlkit==0.13.3
|
|
|
|
| 60 |
tqdm==4.67.1
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
typing_extensions==4.15.0
|
| 64 |
tzdata==2025.2
|
| 65 |
urllib3==2.5.0
|
| 66 |
-
uvicorn==0.
|
| 67 |
websockets==15.0.1
|
|
|
|
| 1 |
aiofiles==24.1.0
|
| 2 |
annotated-types==0.7.0
|
| 3 |
+
anyio==4.11.0
|
|
|
|
| 4 |
Brotli==1.1.0
|
| 5 |
+
certifi==2025.10.5
|
| 6 |
charset-normalizer==3.4.3
|
| 7 |
click==8.3.0
|
| 8 |
+
exceptiongroup==1.3.0
|
| 9 |
+
fastapi==0.118.0
|
| 10 |
ffmpy==0.6.1
|
| 11 |
filelock==3.19.1
|
| 12 |
fsspec==2025.9.0
|
| 13 |
+
gradio==5.49.0
|
| 14 |
+
gradio_client==1.13.3
|
| 15 |
groovy==0.1.2
|
| 16 |
h11==0.16.0
|
|
|
|
| 17 |
hf-xet==1.1.10
|
|
|
|
| 18 |
httpcore==1.0.9
|
| 19 |
httpx==0.28.1
|
| 20 |
+
huggingface-hub==0.35.3
|
|
|
|
| 21 |
idna==3.10
|
| 22 |
Jinja2==3.1.6
|
|
|
|
| 23 |
markdown-it-py==4.0.0
|
| 24 |
+
MarkupSafe==3.0.3
|
|
|
|
| 25 |
mdurl==0.1.2
|
| 26 |
+
mpmath==1.3.0
|
| 27 |
+
networkx==3.4.2
|
| 28 |
numpy==2.2.6
|
| 29 |
+
nvidia-cublas-cu12==12.8.4.1
|
| 30 |
+
nvidia-cuda-cupti-cu12==12.8.90
|
| 31 |
+
nvidia-cuda-nvrtc-cu12==12.8.93
|
| 32 |
+
nvidia-cuda-runtime-cu12==12.8.90
|
| 33 |
+
nvidia-cudnn-cu12==9.10.2.21
|
| 34 |
+
nvidia-cufft-cu12==11.3.3.83
|
| 35 |
+
nvidia-cufile-cu12==1.13.1.3
|
| 36 |
+
nvidia-curand-cu12==10.3.9.90
|
| 37 |
+
nvidia-cusolver-cu12==11.7.3.90
|
| 38 |
+
nvidia-cusparse-cu12==12.5.8.93
|
| 39 |
+
nvidia-cusparselt-cu12==0.7.1
|
| 40 |
+
nvidia-nccl-cu12==2.27.3
|
| 41 |
+
nvidia-nvjitlink-cu12==12.8.93
|
| 42 |
+
nvidia-nvtx-cu12==12.8.90
|
| 43 |
orjson==3.11.3
|
| 44 |
packaging==25.0
|
| 45 |
+
pandas==2.3.3
|
| 46 |
pillow==11.3.0
|
| 47 |
+
pydantic==2.11.10
|
|
|
|
| 48 |
pydantic_core==2.33.2
|
| 49 |
pydub==0.25.1
|
| 50 |
Pygments==2.19.2
|
|
|
|
| 52 |
python-dotenv==1.1.1
|
| 53 |
python-multipart==0.0.20
|
| 54 |
pytz==2025.2
|
| 55 |
+
PyYAML==6.0.3
|
| 56 |
+
regex==2025.9.18
|
| 57 |
requests==2.32.5
|
| 58 |
rich==14.1.0
|
| 59 |
+
ruff==0.14.0
|
| 60 |
safehttpx==0.1.6
|
| 61 |
+
safetensors==0.6.2
|
| 62 |
semantic-version==2.10.0
|
| 63 |
shellingham==1.5.4
|
| 64 |
six==1.17.0
|
| 65 |
+
smolagents==1.22.0
|
| 66 |
sniffio==1.3.1
|
|
|
|
|
|
|
| 67 |
starlette==0.48.0
|
| 68 |
+
sympy==1.14.0
|
| 69 |
+
tokenizers==0.22.1
|
| 70 |
tomlkit==0.13.3
|
| 71 |
+
torch==2.8.0
|
| 72 |
tqdm==4.67.1
|
| 73 |
+
transformers==4.57.0
|
| 74 |
+
triton==3.4.0
|
| 75 |
+
typer==0.19.2
|
| 76 |
+
typing-inspection==0.4.2
|
| 77 |
typing_extensions==4.15.0
|
| 78 |
tzdata==2025.2
|
| 79 |
urllib3==2.5.0
|
| 80 |
+
uvicorn==0.37.0
|
| 81 |
websockets==15.0.1
|