Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import logging
|
| 4 |
-
from typing import Optional
|
|
|
|
| 5 |
|
| 6 |
# Configure logging
|
| 7 |
logging.basicConfig(
|
|
@@ -34,12 +35,12 @@ def initialize_model():
|
|
| 34 |
|
| 35 |
pipe = pipeline(
|
| 36 |
"text-generation",
|
| 37 |
-
model="bigscience/bloom-560m",
|
| 38 |
tokenizer="bigscience/bloom-560m",
|
| 39 |
-
device=-1,
|
| 40 |
max_new_tokens=256,
|
| 41 |
force_download=True,
|
| 42 |
-
low_cpu_mem_usage=True,
|
| 43 |
)
|
| 44 |
logger.info("Model pipeline loaded successfully")
|
| 45 |
return pipe
|
|
@@ -50,7 +51,7 @@ def initialize_model():
|
|
| 50 |
def setup_agent(pipe):
|
| 51 |
"""Setup LangChain agent with the model pipeline"""
|
| 52 |
try:
|
| 53 |
-
from
|
| 54 |
from langchain.agents import initialize_agent
|
| 55 |
from langchain.agents.agent_types import AgentType
|
| 56 |
from langchain.tools import BaseTool
|
|
@@ -58,16 +59,16 @@ def setup_agent(pipe):
|
|
| 58 |
# Initialize LLM
|
| 59 |
llm = HuggingFacePipeline(pipeline=pipe)
|
| 60 |
|
| 61 |
-
# Define the tool
|
| 62 |
class MachineryReportTool(BaseTool):
|
| 63 |
-
name = "machinery_report"
|
| 64 |
-
description = (
|
| 65 |
"Generates a report on mini construction equipment including "
|
| 66 |
"specifications and market analysis."
|
| 67 |
)
|
| 68 |
|
|
|
|
| 69 |
def _run(self, query: str) -> str:
|
| 70 |
-
# Simplified report for memory efficiency
|
| 71 |
return """
|
| 72 |
Mini Construction Equipment Report:
|
| 73 |
1. Basic Gas-Powered Unit: $3,700, 14HP
|
|
@@ -76,7 +77,8 @@ def setup_agent(pipe):
|
|
| 76 |
Market Analysis: 30-40% cheaper than US equivalents
|
| 77 |
"""
|
| 78 |
|
| 79 |
-
|
|
|
|
| 80 |
raise NotImplementedError("Async not supported.")
|
| 81 |
|
| 82 |
# Initialize agent with minimal settings
|
|
@@ -86,7 +88,7 @@ def setup_agent(pipe):
|
|
| 86 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 87 |
verbose=True,
|
| 88 |
max_iterations=1,
|
| 89 |
-
early_stopping_method="generate"
|
| 90 |
)
|
| 91 |
logger.info("Agent initialized successfully")
|
| 92 |
return agent
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import logging
|
| 4 |
+
from typing import Optional, Any
|
| 5 |
+
from typing_extensions import override
|
| 6 |
|
| 7 |
# Configure logging
|
| 8 |
logging.basicConfig(
|
|
|
|
| 35 |
|
| 36 |
pipe = pipeline(
|
| 37 |
"text-generation",
|
| 38 |
+
model="bigscience/bloom-560m",
|
| 39 |
tokenizer="bigscience/bloom-560m",
|
| 40 |
+
device=-1,
|
| 41 |
max_new_tokens=256,
|
| 42 |
force_download=True,
|
| 43 |
+
low_cpu_mem_usage=True,
|
| 44 |
)
|
| 45 |
logger.info("Model pipeline loaded successfully")
|
| 46 |
return pipe
|
|
|
|
| 51 |
def setup_agent(pipe):
|
| 52 |
"""Setup LangChain agent with the model pipeline"""
|
| 53 |
try:
|
| 54 |
+
from langchain_huggingface import HuggingFacePipeline # Updated import
|
| 55 |
from langchain.agents import initialize_agent
|
| 56 |
from langchain.agents.agent_types import AgentType
|
| 57 |
from langchain.tools import BaseTool
|
|
|
|
| 59 |
# Initialize LLM
|
| 60 |
llm = HuggingFacePipeline(pipeline=pipe)
|
| 61 |
|
| 62 |
+
# Define the tool with proper type annotations
|
| 63 |
class MachineryReportTool(BaseTool):
|
| 64 |
+
name: str = "machinery_report" # Type annotation added
|
| 65 |
+
description: str = ( # Type annotation added
|
| 66 |
"Generates a report on mini construction equipment including "
|
| 67 |
"specifications and market analysis."
|
| 68 |
)
|
| 69 |
|
| 70 |
+
@override
|
| 71 |
def _run(self, query: str) -> str:
|
|
|
|
| 72 |
return """
|
| 73 |
Mini Construction Equipment Report:
|
| 74 |
1. Basic Gas-Powered Unit: $3,700, 14HP
|
|
|
|
| 77 |
Market Analysis: 30-40% cheaper than US equivalents
|
| 78 |
"""
|
| 79 |
|
| 80 |
+
@override
|
| 81 |
+
def _arun(self, query: str) -> Any:
|
| 82 |
raise NotImplementedError("Async not supported.")
|
| 83 |
|
| 84 |
# Initialize agent with minimal settings
|
|
|
|
| 88 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 89 |
verbose=True,
|
| 90 |
max_iterations=1,
|
| 91 |
+
early_stopping_method="generate"
|
| 92 |
)
|
| 93 |
logger.info("Agent initialized successfully")
|
| 94 |
return agent
|