Sauten commited on
Commit
7f894b4
·
verified ·
1 Parent(s): 331db0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -93
app.py CHANGED
@@ -3,23 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- import json
7
- from urllib.parse import quote
8
- from bs4 import BeautifulSoup
9
- from duckduckgo_search import DDGS
10
- import random
11
- from typing import Dict, List
12
- import time
13
-
14
-
15
-
16
-
17
-
18
- from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, load_tool, tool, FinalAnswerTool, OpenAIServerModel, PythonInterpreterTool #, #VisitWebpageTool
19
-
20
- from toolVisitWebpage import visit_webpage
21
- from tool_fetch_task_file import fetch_task_file
22
- from tool_read_excel_as_json import read_excel_as_json
23
 
24
  # (Keep Constants as is)
25
  # --- Constants ---
@@ -27,82 +11,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
27
 
28
  # --- Basic Agent Definition ---
29
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
30
-
31
- # model = OpenAIServerModel(
32
- # model_id="gpt-4o",
33
- # temperature = 0.1,
34
- # max_tokens = 2000,
35
- # api_key="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"
36
- # )
37
-
38
- model = OpenAIServerModel(
39
- api_key="fw_3ZSrkw3Qv5eeA1yx65x1eD5H",
40
- api_base="https://api.fireworks.ai/inference/v1",
41
- model_id="accounts/fireworks/models/deepseek-v3",
42
- #temperature = 0.3,
43
- max_tokens = 4000
44
- )
45
- # # #top_p = 1
46
-
47
-
48
- USER_AGENTS = [
49
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
50
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
51
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
52
- "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1",
53
- "Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.5790.136 Mobile Safari/537.36"
54
- ]
55
-
56
-
57
- @tool
58
- def simple_web_search(query: str, num_results: int = 5) -> str:
59
- """Search DuckDuckGo.
60
- Args:
61
- query: Search terms.
62
- num_results: Result count.
63
- """
64
- time.sleep(3)
65
- try:
66
- # Validate inputs
67
- if not query.strip():
68
- return json.dumps({"error": "Empty query string"})
69
-
70
- num_results = max(1, min(10, num_results)) # Limit to 1-10 results
71
-
72
- # Random delay and User-Agent
73
- delay = random.uniform(1.0, 3.0)
74
- user_agent = random.choice(USER_AGENTS)
75
- time.sleep(delay)
76
-
77
- # Perform search
78
- with DDGS(headers={"User-Agent": user_agent}) as ddgs:
79
- results = []
80
- for result in ddgs.text(query, max_results=num_results):
81
- results.append({
82
- 'title': result.get('title', 'No title'),
83
- 'link': result.get('href', '#'),
84
- 'snippet': result.get('body', 'No description')
85
- })
86
- if len(results) >= num_results:
87
- break
88
-
89
- if not results:
90
- return json.dumps({
91
- "error": "No results found",
92
- "query": query,
93
- "user_agent": user_agent
94
- })
95
-
96
- return json.dumps(results)
97
-
98
- except Exception as e:
99
- return json.dumps({
100
- "error": str(e),
101
- "type": type(e).__name__,
102
- "query": query,
103
- "user_agent": user_agent if 'user_agent' in locals() else "Unknown"
104
- })
105
- #simple_web_search = simple_web_search()
106
 
107
  class BasicAgent:
108
  def __init__(self):
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agent import run
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
+ class BasicAgent:
15
+ def __init__(self):
16
+ print("BasicAgent initialized.")
17
+ def __call__(self, question: str) -> str:
18
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
19
+ fixed_answer = run(question)
20
+ print(f"Agent returning fixed answer: {fixed_answer}")
21
+ return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  class BasicAgent:
24
  def __init__(self):