MasterOfHugs commited on
Commit
d87e33a
·
verified ·
1 Parent(s): a3b4729

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -1,37 +1,28 @@
1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- import os
5
  from smolagents.agents import MultiStepAgent
6
- from smolagents.models import HfApiModel
7
- from smolagents.utils import load_json, load_yaml
8
  from Gradio_UI import GradioUI
9
 
10
- # --- Config paths ---
11
- AGENT_JSON_PATH = "agent.json"
12
- PROMPTS_YAML_PATH = "prompts.yaml"
13
- UPLOAD_FOLDER = "uploaded_files"
14
-
15
- # --- Load agent configuration ---
16
- agent_config = load_json(AGENT_JSON_PATH)
17
- prompts_config = load_yaml(PROMPTS_YAML_PATH)
18
 
19
- # --- Initialize the model ---
20
- model_cfg = agent_config["model"]["data"]
21
  model = HfApiModel(
22
- model_id=model_cfg.get("model_id", "bigcode/starcoder"),
23
- max_tokens=model_cfg.get("max_tokens", 1024),
24
- temperature=model_cfg.get("temperature", 0.5),
25
  )
26
 
27
- # --- Initialize the agent ---
28
  agent = MultiStepAgent(
29
  tools=agent_config.get("tools", []),
30
  model=model,
31
- prompt_templates=prompts_config,
32
  max_steps=agent_config.get("max_steps", 6),
33
  )
34
 
35
- # --- Launch Gradio interface ---
36
- ui = GradioUI(agent, file_upload_folder=UPLOAD_FOLDER)
37
- ui.launch(debug=True, share=True)
 
1
+ import json
 
 
 
2
  from smolagents.agents import MultiStepAgent
3
+ from smolagents.models import HfApiModel # <- important, c'est le vrai model object
 
4
  from Gradio_UI import GradioUI
5
 
6
+ # Charge la config de l'agent
7
+ with open("agent.json") as f:
8
+ agent_config = json.load(f)
 
 
 
 
 
9
 
10
+ # Instancie le modèle
11
+ model_cfg = agent_config.get("model", {})
12
  model = HfApiModel(
13
+ model_id=model_cfg["data"]["model_id"],
14
+ max_tokens=model_cfg["data"].get("max_tokens", 2048),
15
+ temperature=model_cfg["data"].get("temperature", 0.5),
16
  )
17
 
18
+ # Initialise l'agent
19
  agent = MultiStepAgent(
20
  tools=agent_config.get("tools", []),
21
  model=model,
22
+ prompt_config_path="prompts.yaml",
23
  max_steps=agent_config.get("max_steps", 6),
24
  )
25
 
26
+ # Lance l'interface Gradio
27
+ ui = GradioUI(agent, file_upload_folder="uploads")
28
+ ui.launch(share=True)