company description using DuckDuckGo
Browse filesAbandoned the LLM solution for generating a company description. Now using DuckDuckGo's Instant Answer API
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import yaml
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from PIL import Image
|
| 8 |
from io import BytesIO
|
| 9 |
-
from transformers import pipeline
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
@@ -43,27 +42,26 @@ def company_logos(company_name: str) -> Image.Image:
|
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def company_description(company_name: str) -> str:
|
| 46 |
-
"""
|
| 47 |
|
| 48 |
-
Args:
|
| 49 |
company_name: The name of the company.
|
| 50 |
|
| 51 |
Returns:
|
| 52 |
A short description of the company.
|
| 53 |
"""
|
| 54 |
-
|
| 55 |
-
prompt = (
|
| 56 |
-
f"Provide a short summary about {company_name}. Include:\n"
|
| 57 |
-
"- One sentence describing the company's main product or service.\n"
|
| 58 |
-
"- Two sentences summarizing the company's history.\n"
|
| 59 |
-
"- One sentence about the latest news related to the company."
|
| 60 |
-
)
|
| 61 |
|
| 62 |
try:
|
| 63 |
-
response =
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
-
return f"Error
|
|
|
|
| 67 |
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
|
|
@@ -78,8 +76,8 @@ custom_role_conversions=None,
|
|
| 78 |
)
|
| 79 |
|
| 80 |
|
| 81 |
-
# Import tool from Hub
|
| 82 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 83 |
|
| 84 |
with open("prompts.yaml", 'r') as stream:
|
| 85 |
prompt_templates = yaml.safe_load(stream)
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from PIL import Image
|
| 8 |
from io import BytesIO
|
|
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def company_description(company_name: str) -> str:
|
| 45 |
+
"""Fetches a company description using DuckDuckGo's Instant Answer API.
|
| 46 |
|
| 47 |
+
Args:
|
| 48 |
company_name: The name of the company.
|
| 49 |
|
| 50 |
Returns:
|
| 51 |
A short description of the company.
|
| 52 |
"""
|
| 53 |
+
url = f"https://api.duckduckgo.com/?q={company_name}+company&format=json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
try:
|
| 56 |
+
response = requests.get(url)
|
| 57 |
+
if response.status_code == 200:
|
| 58 |
+
data = response.json()
|
| 59 |
+
return data.get("AbstractText", "No description available.")
|
| 60 |
+
else:
|
| 61 |
+
return "Company description not found."
|
| 62 |
except Exception as e:
|
| 63 |
+
return f"Error fetching company description: {str(e)}"
|
| 64 |
+
|
| 65 |
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
|
| 79 |
+
# # Import tool from Hub
|
| 80 |
+
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 81 |
|
| 82 |
with open("prompts.yaml", 'r') as stream:
|
| 83 |
prompt_templates = yaml.safe_load(stream)
|