Dave67350 commited on
Commit
6a17dd0
·
verified ·
1 Parent(s): f0b643e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -6
app.py CHANGED
@@ -34,14 +34,46 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
- final_answer = FinalAnswerTool()
38
- model = HfApiModel(
39
- max_tokens=2096,
40
- temperature=0.5,
41
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
42
- custom_role_conversions=None,
43
  )
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Import tool from Hub
47
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ # Load AI Regulation Model (No HF Token required)
38
+ ai_regulation_model = HfApiModel(
39
+ max_tokens=500,
40
+ temperature=0.5,
41
+ model_id="Orcawise/eu_ai_act_using_finetuned_gemma"
 
42
  )
43
 
44
+ @tool
45
+ def ai_act_search_tool(query: str, max_results: int = 5) -> dict:
46
+ """
47
+ Searches for AI Act insights using an AI model and DuckDuckGo.
48
+
49
+ Arguments:
50
+ query: (str) The search query related to the AI Act.
51
+ max_results: (int) The maximum number of search results to return.
52
+
53
+ Returns:
54
+ (dict) A dictionary containing:
55
+ - "ai_insight": AI-generated insights on the AI Act query.
56
+ - "articles": A list of URLs to relevant articles.
57
+ """
58
+ # Step 1: Get AI Model Insights
59
+ ai_response = ai_regulation_model.generate(prompt=f"Provide insights on: {query} related to the AI Act.")
60
+ ai_insight = ai_response["generated_text"] if isinstance(ai_response, dict) and "generated_text" in ai_response else "No AI insights available."
61
+
62
+ # Step 2: Perform DuckDuckGo Search
63
+ try:
64
+ with DDGS() as ddgs:
65
+ search_results = ddgs.text(query + " AI Act", max_results)
66
+ articles = [{"title": result["title"], "link": result["href"]} for result in search_results] if search_results else []
67
+ except Exception as e:
68
+ articles = []
69
+ print(f"Error in DuckDuckGo search: {e}")
70
+
71
+ # Step 3: Return Combined Results
72
+ return {
73
+ "ai_insight": ai_insight,
74
+ "articles": articles
75
+ }
76
+
77
 
78
  # Import tool from Hub
79
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)