Spaces:
Running
Running
Commit
·
33eaa22
1
Parent(s):
3f0e775
update
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from gradio import ChatMessage
|
|
6 |
from smolagents.gradio_ui import stream_to_gradio
|
7 |
|
8 |
from agents.all_agents import get_master_agent
|
9 |
-
from llm import
|
10 |
|
11 |
|
12 |
gr.set_static_paths(paths=["images/"])
|
@@ -23,8 +23,9 @@ def resize_image(image):
|
|
23 |
return image
|
24 |
|
25 |
|
26 |
-
def chat_interface_fn(input_request, history: List[ChatMessage], gallery):
|
27 |
-
|
|
|
28 |
if gallery is None:
|
29 |
gallery = []
|
30 |
else:
|
@@ -123,6 +124,26 @@ with gr.Blocks() as demo:
|
|
123 |
</div>
|
124 |
""",
|
125 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
output_gallery = gr.Gallery(label="Images generated by the agent (do not put images)", type="pil", format="png")
|
127 |
textbox = gr.MultimodalTextbox()
|
128 |
gr.ChatInterface(
|
@@ -130,7 +151,7 @@ with gr.Blocks() as demo:
|
|
130 |
type="messages",
|
131 |
multimodal=True,
|
132 |
textbox=textbox,
|
133 |
-
additional_inputs=[output_gallery],
|
134 |
additional_outputs=[output_gallery],
|
135 |
)
|
136 |
|
|
|
6 |
from smolagents.gradio_ui import stream_to_gradio
|
7 |
|
8 |
from agents.all_agents import get_master_agent
|
9 |
+
from llm import ANTHROPIC_MODEL_IDS, get_anthropic_model
|
10 |
|
11 |
|
12 |
gr.set_static_paths(paths=["images/"])
|
|
|
23 |
return image
|
24 |
|
25 |
|
26 |
+
def chat_interface_fn(input_request, history: List[ChatMessage], gallery, anthropic_api_key, anthropic_model_id):
|
27 |
+
model = get_anthropic_model(anthropic_model_id, anthropic_api_key)
|
28 |
+
agent = get_master_agent(model)
|
29 |
if gallery is None:
|
30 |
gallery = []
|
31 |
else:
|
|
|
124 |
</div>
|
125 |
""",
|
126 |
)
|
127 |
+
gr.Markdown(
|
128 |
+
"""
|
129 |
+
## Update 17/06/2025
|
130 |
+
This Space was originally a Hackathon submission, funded with Anthropic Free Credits.<br>
|
131 |
+
Due to the high popularity of the Space, unfortunately I can't fund personally the credits anymore.<br>
|
132 |
+
I have added below the ability to add your own Anthropic API Key and select the model to use.<br>
|
133 |
+
"""
|
134 |
+
)
|
135 |
+
anthropic_api_key = gr.Textbox(label="Anthropic API Key")
|
136 |
+
anthropic_model_id = gr.Dropdown(label="Anthropic Model", choices=ANTHROPIC_MODEL_IDS)
|
137 |
+
gr.Markdown(
|
138 |
+
"""
|
139 |
+
## Future plans
|
140 |
+
I plan to continue developing this Space on a more personal space here : https://huggingface.co/spaces/stevenbucaille/ScouterAI <br>
|
141 |
+
This Space will be powered with ZeroGPU and have more LLM options.<br>
|
142 |
+
Don't hesitate to like this other Space or reach out to me on <a href="https://www.linkedin.com/in/sbucaille/">LinkedIn</a> if you have any questions or feedback!<br>
|
143 |
+
Stay tuned!
|
144 |
+
<br>
|
145 |
+
"""
|
146 |
+
)
|
147 |
output_gallery = gr.Gallery(label="Images generated by the agent (do not put images)", type="pil", format="png")
|
148 |
textbox = gr.MultimodalTextbox()
|
149 |
gr.ChatInterface(
|
|
|
151 |
type="messages",
|
152 |
multimodal=True,
|
153 |
textbox=textbox,
|
154 |
+
additional_inputs=[output_gallery, anthropic_api_key, anthropic_model_id],
|
155 |
additional_outputs=[output_gallery],
|
156 |
)
|
157 |
|
llm.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
from smolagents import LiteLLMModel
|
4 |
|
5 |
|
6 |
-
|
7 |
-
"
|
8 |
-
"
|
9 |
-
"
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
|
17 |
-
def
|
|
|
|
|
18 |
model = LiteLLMModel(
|
19 |
-
|
20 |
-
|
21 |
-
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
22 |
-
# reasoning_effort="low",
|
23 |
)
|
24 |
-
print("Loaded LLM model")
|
25 |
return model
|
|
|
|
|
|
|
1 |
from smolagents import LiteLLMModel
|
2 |
|
3 |
|
4 |
+
ANTHROPIC_MODEL_IDS = [
|
5 |
+
"claude-opus-4-20250514",
|
6 |
+
"claude-sonnet-4-20250514",
|
7 |
+
"claude-3-7-sonnet-latest",
|
8 |
+
"claude-3-5-haiku-latest",
|
9 |
+
"claude-3-5-sonnet-latest",
|
10 |
+
"claude-3-5-sonnet-20240620",
|
11 |
+
"claude-3-opus-latest",
|
12 |
+
"claude-3-sonnet-20240229",
|
13 |
+
"claude-3-haiku-20240307",
|
14 |
+
]
|
15 |
|
16 |
|
17 |
+
def get_anthropic_model(model_id, anthropic_api_key):
|
18 |
+
if model_id not in ANTHROPIC_MODEL_IDS:
|
19 |
+
raise ValueError(f"Model {model_id} not found in Anthropic model IDs")
|
20 |
model = LiteLLMModel(
|
21 |
+
model_id=model_id,
|
22 |
+
api_key=anthropic_api_key,
|
|
|
|
|
23 |
)
|
|
|
24 |
return model
|