ArslanFOX commited on
Commit
cced9c5
·
verified ·
1 Parent(s): 21c40f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -1,9 +1,13 @@
1
- # app.py
2
  import os
3
  from smolagents import CodeAgent, HfApiModel, tool
4
  import datetime
5
  import pytz
6
- import gradio as gr
 
 
 
 
 
7
 
8
  @tool
9
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -26,16 +30,17 @@ def final_answer(answer: str) -> str:
26
  """
27
  return answer
28
 
29
- model = HfApiModel(
30
- max_tokens=100,
31
- temperature=0.5,
32
- model_id='Qwen/Qwen2.5-Coder-7B-Instruct',
33
- )
 
 
 
34
 
35
- prompt_templates = {
36
- "default": "Answer: {{question}}",
37
- "system_prompt": "You are a helpful assistant. Use tools if necessary to answer the question."
38
- }
39
 
40
  agent = CodeAgent(
41
  model=model,
@@ -45,11 +50,4 @@ agent = CodeAgent(
45
  prompt_templates=prompt_templates,
46
  )
47
 
48
- def process_input(user_input):
49
- try:
50
- response = agent.run(user_input)
51
- return response
52
- except Exception as e:
53
- return f"Error: {str(e)}"
54
-
55
- gr.Interface(fn=process_input, inputs="text", outputs="text").launch()
 
 
1
  import os
2
  from smolagents import CodeAgent, HfApiModel, tool
3
  import datetime
4
  import pytz
5
+ import yaml
6
+ from Gradio_UI import GradioUI
7
+ from tools.final_answer import FinalAnswerTool
8
+
9
+ # Выводим токен для отладки (в логах он будет скрыт как секрет)
10
+ print("HF_TOKEN from environment:", "Set" if os.getenv("HF_TOKEN") else "Not set")
11
 
12
  @tool
13
  def get_current_time_in_timezone(timezone: str) -> str:
 
30
  """
31
  return answer
32
 
33
+ try:
34
+ model = HfApiModel(
35
+ max_tokens=100,
36
+ temperature=0.5,
37
+ model_id='Qwen/Qwen2.5-Coder-7B-Instruct',
38
+ )
39
+ except Exception as e:
40
+ print(f"Error initializing model: {str(e)}")
41
 
42
+ with open("prompts.yaml", 'r') as stream:
43
+ prompt_templates = yaml.safe_load(stream)
 
 
44
 
45
  agent = CodeAgent(
46
  model=model,
 
50
  prompt_templates=prompt_templates,
51
  )
52
 
53
+ GradioUI(agent).launch()