fixed error in generating company description
Browse files
app.py
CHANGED
|
@@ -9,6 +9,9 @@ from io import BytesIO
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
@tool
|
| 13 |
def company_logos(company_name: str) -> Image.Image:
|
| 14 |
"""A tool that retrieves the logo of a given company using the Clearbit Logo API.
|
|
@@ -39,18 +42,27 @@ def company_logos(company_name: str) -> Image.Image:
|
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def company_description(company_name: str) -> str:
|
| 42 |
-
"""
|
| 43 |
-
|
| 44 |
Args:
|
| 45 |
company_name: The name of the company.
|
| 46 |
|
| 47 |
Returns:
|
| 48 |
-
A short description of the company
|
| 49 |
"""
|
| 50 |
|
| 51 |
-
prompt =
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
final_answer = FinalAnswerTool()
|
| 56 |
|
|
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
+
# Load the text generation pipeline for LLM
|
| 13 |
+
llm = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 14 |
+
|
| 15 |
@tool
|
| 16 |
def company_logos(company_name: str) -> Image.Image:
|
| 17 |
"""A tool that retrieves the logo of a given company using the Clearbit Logo API.
|
|
|
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def company_description(company_name: str) -> str:
|
| 45 |
+
"""Generates a short company description using an LLM.
|
| 46 |
+
|
| 47 |
Args:
|
| 48 |
company_name: The name of the company.
|
| 49 |
|
| 50 |
Returns:
|
| 51 |
+
A short description of the company.
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
prompt = (
|
| 55 |
+
f"Provide a short summary about {company_name}. Include:\n"
|
| 56 |
+
"- One sentence describing the company's main product or service.\n"
|
| 57 |
+
"- Two sentences summarizing the company's history.\n"
|
| 58 |
+
"- One sentence about the latest news related to the company."
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
response = llm(prompt, max_length=150, do_sample=True)
|
| 63 |
+
return response[0]["generated_text"]
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"Error generating description for {company_name}: {str(e)}"
|
| 66 |
|
| 67 |
final_answer = FinalAnswerTool()
|
| 68 |
|