Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1948,7 +1948,6 @@ def get_pdf_content_summary(pdf_filename):
|
|
| 1948 |
# Return summary for the requested PDF
|
| 1949 |
return summaries.get(pdf_filename, "No summary available for this PDF.")
|
| 1950 |
|
| 1951 |
-
# Function to process message in the main chatbot
|
| 1952 |
# Function to process message in the main chatbot
|
| 1953 |
def process_message(message, history):
|
| 1954 |
"""Process messages for the main chatbot interface"""
|
|
@@ -1961,102 +1960,102 @@ def process_message(message, history):
|
|
| 1961 |
# Store message in lowercase for easier matching
|
| 1962 |
message_lower = message.lower()
|
| 1963 |
|
| 1964 |
-
#
|
| 1965 |
-
|
| 1966 |
-
|
| 1967 |
-
|
| 1968 |
-
|
| 1969 |
-
|
| 1970 |
-
system_prompt = """You are Ginnie, an expert ABB product assistant.
|
| 1971 |
-
Your purpose is to help users find and understand ABB products based on catalog information.
|
| 1972 |
-
Be professional, helpful, and concise in your responses.
|
| 1973 |
-
If you don't know something, be honest about it but try to provide alternative information that might help.
|
| 1974 |
-
Use bullet points for lists and keep your responses focused on ABB products and solutions."""
|
| 1975 |
-
|
| 1976 |
-
# Prepare prompt with context from previous messages
|
| 1977 |
-
context = ""
|
| 1978 |
-
if len(history) > 1:
|
| 1979 |
-
for i in range(max(0, len(history)-4), len(history)-1):
|
| 1980 |
-
if history[i][0] is not None:
|
| 1981 |
-
context += f"User: {history[i][0]}\n"
|
| 1982 |
-
if history[i][1] is not None:
|
| 1983 |
-
context += f"Assistant: {history[i][1]}\n"
|
| 1984 |
-
|
| 1985 |
-
user_prompt = f"""Previous conversation:
|
| 1986 |
-
{context}
|
| 1987 |
-
|
| 1988 |
-
Current message: {message}
|
| 1989 |
-
|
| 1990 |
-
Respond to the user as Ginnie, the ABB product assistant. If the query is about a specific ABB product, include key specifications and use cases."""
|
| 1991 |
-
|
| 1992 |
-
response = client.chat.completions.create(
|
| 1993 |
-
model="gpt-3.5-turbo",
|
| 1994 |
-
messages=[
|
| 1995 |
-
{"role": "system", "content": system_prompt},
|
| 1996 |
-
{"role": "user", "content": user_prompt}
|
| 1997 |
-
],
|
| 1998 |
-
temperature=0.7,
|
| 1999 |
-
max_tokens=500
|
| 2000 |
-
)
|
| 2001 |
-
|
| 2002 |
-
# Extract the response
|
| 2003 |
-
ai_response = response.choices[0].message.content
|
| 2004 |
-
|
| 2005 |
-
except Exception as e:
|
| 2006 |
-
print(f"Error calling AI service: {e}")
|
| 2007 |
-
ai_response = None # Initialize response as None to check later if a fallback was matched
|
| 2008 |
-
|
| 2009 |
-
# Check for specific PSTX softstarter questions and provide fallback answers
|
| 2010 |
-
|
| 2011 |
-
# Predefined fallback answers for specific PSTX softstarter questions
|
| 2012 |
-
if "pstx" in message_lower:
|
| 2013 |
-
if any(word in message_lower for word in ["voltage", "current"]):
|
| 2014 |
-
ai_response = """The PSTX softstarter supports the following voltage and current ratings:
|
| 2015 |
• Voltage Rating: The PSTX softstarter operates at 208 to 600 V AC with a rated insulation voltage of 690 V.
|
| 2016 |
• Current Rating: The operational current ranges from 30 A to 1250 A, depending on the model.
|
| 2017 |
• Control Supply Voltage: 100–250 V AC, 50/60 Hz.
|
| 2018 |
• Number of Starts per Hour: 10 starts for smaller models (PSTX20 to PSTX250) and 6 starts for larger models (PSTX300 to PSTX1000)."""
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
|
| 2022 |
• Current limit settings, which allow the motor to start even in weak electrical networks.
|
| 2023 |
• Dual current limit and current limit ramp, enabling gradual voltage increase and smooth motor acceleration.
|
| 2024 |
• Soft start with voltage ramp that ensures a controlled increase in voltage, preventing sudden power surges.
|
| 2025 |
• Full voltage start mode allows the motor to reach full speed quickly while managing the current to avoid excessive inrush."""
|
| 2026 |
-
|
| 2027 |
-
|
| 2028 |
-
|
| 2029 |
• Input and output field wiring terminals for power and control connections.
|
| 2030 |
• Control power transformer for control voltage regulation.
|
| 2031 |
• Breaker/disconnect mechanisms for safety.
|
| 2032 |
• Grounding is essential and is facilitated by equipment grounding lugs.
|
| 2033 |
• Control relays and terminal blocks manage connections for external devices like start/stop pushbuttons, pilot lights, and selector switches.
|
| 2034 |
• Cable Size Requirements: Based on UL508A standards, incoming and load cable sizes depend on the motor's power rating (e.g., for 50 HP at 480V, incoming cables can be up to 1/0 AWG)."""
|
| 2035 |
-
|
| 2036 |
-
|
| 2037 |
-
|
| 2038 |
• Activating the bypass contactor once the motor reaches full speed.
|
| 2039 |
• Reducing energy loss by switching off the softstarter's thyristors, preventing unnecessary heat generation.
|
| 2040 |
• Extending product lifespan by minimizing component wear compared to continuous thyristor switching.
|
| 2041 |
• Saving space and installation time since the bypass is integrated into the softstarter, eliminating the need for an external bypass circuit."""
|
| 2042 |
-
|
| 2043 |
-
|
| 2044 |
-
|
| 2045 |
• Allows the motor to run at reduced speed in both forward and reverse directions without needing a variable speed drive.
|
| 2046 |
• Is useful for precisely positioning conveyor belts and cranes before full operation.
|
| 2047 |
• Helps in maintenance scenarios where manual control of movement is needed.
|
| 2048 |
• Eliminates the need for an external drive system, making the installation simpler and more cost-effective."""
|
| 2049 |
-
|
| 2050 |
-
|
| 2051 |
-
|
| 2052 |
• Operating with one phase missing if a thyristor short-circuits, allowing the system to continue running instead of shutting down immediately.
|
| 2053 |
• Helping in applications where downtime is costly, such as in manufacturing plants and critical industrial processes.
|
| 2054 |
• Preventing unplanned stoppages by keeping the system functional until maintenance can be scheduled.
|
| 2055 |
• Improving system resilience, reducing the impact of single-component failures."""
|
| 2056 |
-
|
| 2057 |
-
|
| 2058 |
-
|
| 2059 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2060 |
|
| 2061 |
# Update history with assistant response
|
| 2062 |
history[-1][1] = ai_response
|
|
@@ -2066,10 +2065,6 @@ def process_message(message, history):
|
|
| 2066 |
|
| 2067 |
return history
|
| 2068 |
|
| 2069 |
-
# Function to reset chat
|
| 2070 |
-
def reset_chat(history):
|
| 2071 |
-
"""Reset the chat history"""
|
| 2072 |
-
return []
|
| 2073 |
|
| 2074 |
# Function to setup system and update status
|
| 2075 |
def setup_and_update():
|
|
|
|
| 1948 |
# Return summary for the requested PDF
|
| 1949 |
return summaries.get(pdf_filename, "No summary available for this PDF.")
|
| 1950 |
|
|
|
|
| 1951 |
# Function to process message in the main chatbot
|
| 1952 |
def process_message(message, history):
|
| 1953 |
"""Process messages for the main chatbot interface"""
|
|
|
|
| 1960 |
# Store message in lowercase for easier matching
|
| 1961 |
message_lower = message.lower()
|
| 1962 |
|
| 1963 |
+
# First check if we should use predefined answers for PSTX questions
|
| 1964 |
+
# (This moves the fallback check before the API call)
|
| 1965 |
+
ai_response = None
|
| 1966 |
+
if "pstx" in message_lower:
|
| 1967 |
+
if any(word in message_lower for word in ["voltage", "current"]):
|
| 1968 |
+
ai_response = """The PSTX softstarter supports the following voltage and current ratings:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1969 |
• Voltage Rating: The PSTX softstarter operates at 208 to 600 V AC with a rated insulation voltage of 690 V.
|
| 1970 |
• Current Rating: The operational current ranges from 30 A to 1250 A, depending on the model.
|
| 1971 |
• Control Supply Voltage: 100–250 V AC, 50/60 Hz.
|
| 1972 |
• Number of Starts per Hour: 10 starts for smaller models (PSTX20 to PSTX250) and 6 starts for larger models (PSTX300 to PSTX1000)."""
|
| 1973 |
+
|
| 1974 |
+
elif ("inrush" in message_lower and ("current" in message_lower or "startup" in message_lower)):
|
| 1975 |
+
ai_response = """The PSTX softstarter handles high inrush currents during motor startup through:
|
| 1976 |
• Current limit settings, which allow the motor to start even in weak electrical networks.
|
| 1977 |
• Dual current limit and current limit ramp, enabling gradual voltage increase and smooth motor acceleration.
|
| 1978 |
• Soft start with voltage ramp that ensures a controlled increase in voltage, preventing sudden power surges.
|
| 1979 |
• Full voltage start mode allows the motor to reach full speed quickly while managing the current to avoid excessive inrush."""
|
| 1980 |
+
|
| 1981 |
+
elif "wiring" in message_lower:
|
| 1982 |
+
ai_response = """Wiring requirements for installing a PSTX softstarter include:
|
| 1983 |
• Input and output field wiring terminals for power and control connections.
|
| 1984 |
• Control power transformer for control voltage regulation.
|
| 1985 |
• Breaker/disconnect mechanisms for safety.
|
| 1986 |
• Grounding is essential and is facilitated by equipment grounding lugs.
|
| 1987 |
• Control relays and terminal blocks manage connections for external devices like start/stop pushbuttons, pilot lights, and selector switches.
|
| 1988 |
• Cable Size Requirements: Based on UL508A standards, incoming and load cable sizes depend on the motor's power rating (e.g., for 50 HP at 480V, incoming cables can be up to 1/0 AWG)."""
|
| 1989 |
+
|
| 1990 |
+
elif "bypass" in message_lower:
|
| 1991 |
+
ai_response = """The built-in bypass in the PSTX softstarter enhances energy efficiency by:
|
| 1992 |
• Activating the bypass contactor once the motor reaches full speed.
|
| 1993 |
• Reducing energy loss by switching off the softstarter's thyristors, preventing unnecessary heat generation.
|
| 1994 |
• Extending product lifespan by minimizing component wear compared to continuous thyristor switching.
|
| 1995 |
• Saving space and installation time since the bypass is integrated into the softstarter, eliminating the need for an external bypass circuit."""
|
| 1996 |
+
|
| 1997 |
+
elif ("jog" in message_lower and ("slow" in message_lower or "speed" in message_lower)):
|
| 1998 |
+
ai_response = """The "jog with slow speed" feature of the PSTX softstarter:
|
| 1999 |
• Allows the motor to run at reduced speed in both forward and reverse directions without needing a variable speed drive.
|
| 2000 |
• Is useful for precisely positioning conveyor belts and cranes before full operation.
|
| 2001 |
• Helps in maintenance scenarios where manual control of movement is needed.
|
| 2002 |
• Eliminates the need for an external drive system, making the installation simpler and more cost-effective."""
|
| 2003 |
+
|
| 2004 |
+
elif ("limp" in message_lower and ("mode" in message_lower or "fault" in message_lower)):
|
| 2005 |
+
ai_response = """The limp mode feature of the PSTX softstarter ensures continuous operation in case of faults by:
|
| 2006 |
• Operating with one phase missing if a thyristor short-circuits, allowing the system to continue running instead of shutting down immediately.
|
| 2007 |
• Helping in applications where downtime is costly, such as in manufacturing plants and critical industrial processes.
|
| 2008 |
• Preventing unplanned stoppages by keeping the system functional until maintenance can be scheduled.
|
| 2009 |
• Improving system resilience, reducing the impact of single-component failures."""
|
| 2010 |
+
|
| 2011 |
+
# Only try API if we don't already have a predefined answer
|
| 2012 |
+
if ai_response is None:
|
| 2013 |
+
try:
|
| 2014 |
+
# Get OpenAI client
|
| 2015 |
+
client = get_openai_client()
|
| 2016 |
+
|
| 2017 |
+
# Call OpenAI API
|
| 2018 |
+
system_prompt = """You are Ginnie, an expert ABB product assistant.
|
| 2019 |
+
Your purpose is to help users find and understand ABB products based on catalog information.
|
| 2020 |
+
Be professional, helpful, and concise in your responses.
|
| 2021 |
+
If you don't know something, be honest about it but try to provide alternative information that might help.
|
| 2022 |
+
Use bullet points for lists and keep your responses focused on ABB products and solutions."""
|
| 2023 |
+
|
| 2024 |
+
# Prepare prompt with context from previous messages
|
| 2025 |
+
context = ""
|
| 2026 |
+
if len(history) > 1:
|
| 2027 |
+
for i in range(max(0, len(history)-4), len(history)-1):
|
| 2028 |
+
if history[i][0] is not None:
|
| 2029 |
+
context += f"User: {history[i][0]}\n"
|
| 2030 |
+
if history[i][1] is not None:
|
| 2031 |
+
context += f"Assistant: {history[i][1]}\n"
|
| 2032 |
+
|
| 2033 |
+
user_prompt = f"""Previous conversation:
|
| 2034 |
+
{context}
|
| 2035 |
+
|
| 2036 |
+
Current message: {message}
|
| 2037 |
+
|
| 2038 |
+
Respond to the user as Ginnie, the ABB product assistant. If the query is about a specific ABB product, include key specifications and use cases."""
|
| 2039 |
+
|
| 2040 |
+
response = client.chat.completions.create(
|
| 2041 |
+
model="gpt-3.5-turbo",
|
| 2042 |
+
messages=[
|
| 2043 |
+
{"role": "system", "content": system_prompt},
|
| 2044 |
+
{"role": "user", "content": user_prompt}
|
| 2045 |
+
],
|
| 2046 |
+
temperature=0.7,
|
| 2047 |
+
max_tokens=500
|
| 2048 |
+
)
|
| 2049 |
+
|
| 2050 |
+
# Extract the response
|
| 2051 |
+
ai_response = response.choices[0].message.content
|
| 2052 |
+
|
| 2053 |
+
except Exception as e:
|
| 2054 |
+
print(f"Error calling AI service: {e}")
|
| 2055 |
+
|
| 2056 |
+
# If we reach here, the API failed and we don't have a predefined answer
|
| 2057 |
+
if ai_response is None:
|
| 2058 |
+
ai_response = "I apologize, but I'm having trouble connecting to my knowledge base at the moment. Please try again in a few moments or try rephrasing your question."
|
| 2059 |
|
| 2060 |
# Update history with assistant response
|
| 2061 |
history[-1][1] = ai_response
|
|
|
|
| 2065 |
|
| 2066 |
return history
|
| 2067 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2068 |
|
| 2069 |
# Function to setup system and update status
|
| 2070 |
def setup_and_update():
|