MasterOfHugs commited on
Commit
6f2e40d
·
verified ·
1 Parent(s): 81a9b66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -29
app.py CHANGED
@@ -1,36 +1,37 @@
1
- import yaml
2
- from smolagents import CodeAgent, tool
3
 
4
- # Définition d’un outil simple
5
- @tool
6
- def visit_webpage(url: str) -> str:
7
- """
8
- Visit a webpage and return its content.
9
 
10
- Args:
11
- url (str): The URL to visit.
 
 
12
 
13
- Returns:
14
- str: The full HTML content of the page.
15
- """
16
- import requests
17
- response = requests.get(url)
18
- response.raise_for_status()
19
- return response.text
20
 
21
- # Charger les prompts depuis prompts.yaml
22
- with open("prompts.yaml", "r", encoding="utf-8") as f:
23
- prompts = yaml.safe_load(f)
 
 
 
 
24
 
25
- # Créer l’agent avec le system_prompt depuis le yaml
26
- agent = CodeAgent(
27
- tools=[visit_webpage],
28
- system_prompt=prompts["system_prompt"]
 
 
29
  )
30
 
31
- if __name__ == "__main__":
32
- print("===== Application Startup =====")
33
- task = "Visit https://example.com and summarize the page."
34
- result = agent.run(task)
35
- print("===== Final Answer =====")
36
- print(result)
 
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)