Update app.py
Browse files
app.py
CHANGED
@@ -941,49 +941,49 @@ class TinkerIQApp:
|
|
941 |
return history, ""
|
942 |
|
943 |
def handle_text_conversation(self, message: str) -> str:
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
📋 **Current BOM Summary:**
|
965 |
-
- Project: {bom_summary.get('project_name', 'Unknown')}
|
966 |
-
- Components: {bom_summary.get('component_count', 0)}
|
967 |
-
- Total Cost: ${bom_summary.get('total_cost', 0):.2f}
|
968 |
-
|
969 |
-
Use the 'BOM Management' tab to export or modify the BOM.
|
970 |
-
"""
|
|
|
|
|
|
|
|
|
971 |
else:
|
972 |
-
return "
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
- 💡 **Recommendations**: Component suggestions and improvements
|
984 |
-
|
985 |
-
What would you like to work on today?
|
986 |
-
"""
|
987 |
|
988 |
def format_analysis_response(self, analysis_result: Dict) -> str:
|
989 |
"""Format circuit analysis response for chat display"""
|
|
|
941 |
return history, ""
|
942 |
|
943 |
def handle_text_conversation(self, message: str) -> str:
|
944 |
+
"""Handle text-only conversations using AI intelligence"""
|
945 |
+
try:
|
946 |
+
# Use AI to understand and respond to the message
|
947 |
+
return self._generate_ai_response(message)
|
948 |
+
except Exception as e:
|
949 |
+
print(f"Error in AI response generation: {e}")
|
950 |
+
return self._fallback_response(message)
|
951 |
+
|
952 |
+
# Check for code generation requests
|
953 |
+
if any(word in message_lower for word in ["code", "program", "sketch", "arduino", "esp32"]):
|
954 |
+
if self.session_state.get("last_analysis"):
|
955 |
+
return "🔧 I can generate code for your circuit! Please use the 'Code Generation' tab to specify platform and features."
|
956 |
+
else:
|
957 |
+
return "📷 Please upload and analyze a circuit image first, then I can generate code for it."
|
958 |
+
|
959 |
+
# Check for BOM requests
|
960 |
+
elif any(word in message_lower for word in ["bom", "bill of materials", "parts", "components", "cost"]):
|
961 |
+
if self.session_state.get("current_bom"):
|
962 |
+
bom_summary = self.session_state["current_bom"]
|
963 |
+
return f"""
|
964 |
+
📋 **Current BOM Summary:**
|
965 |
+
- Project: {bom_summary.get('project_name', 'Unknown')}
|
966 |
+
- Components: {bom_summary.get('component_count', 0)}
|
967 |
+
- Total Cost: ${bom_summary.get('total_cost', 0):.2f}
|
968 |
+
|
969 |
+
Use the 'BOM Management' tab to export or modify the BOM.
|
970 |
+
"""
|
971 |
+
else:
|
972 |
+
return "📷 Please analyze a circuit first to generate a Bill of Materials."
|
973 |
+
|
974 |
+
# General responses
|
975 |
else:
|
976 |
+
return """
|
977 |
+
🤖 **TinkerIQ Assistant Ready!**
|
978 |
+
|
979 |
+
I can help you with:
|
980 |
+
- 📷 **Circuit Analysis**: Upload circuit images for detailed analysis
|
981 |
+
- 🔧 **Code Generation**: Generate Arduino/ESP32 code for your circuits
|
982 |
+
- 📋 **BOM Creation**: Automatic parts lists with pricing
|
983 |
+
- 💡 **Recommendations**: Component suggestions and improvements
|
984 |
+
|
985 |
+
What would you like to work on today?
|
986 |
+
"""
|
|
|
|
|
|
|
|
|
987 |
|
988 |
def format_analysis_response(self, analysis_result: Dict) -> str:
|
989 |
"""Format circuit analysis response for chat display"""
|