Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,10 @@ import gradio as gr
|
|
| 4 |
import time
|
| 5 |
import re
|
| 6 |
import os
|
|
|
|
|
|
|
| 7 |
|
|
|
|
| 8 |
API_BASE_URL = "https://sale-agent-m179.onrender.com"
|
| 9 |
|
| 10 |
|
|
@@ -57,14 +60,15 @@ def respond_to_chat(message, history, state, selected_model, debug_mode):
|
|
| 57 |
j = resp.json()
|
| 58 |
response = j.get("response", "")
|
| 59 |
specs_advantages = j.get("specs_advantages")
|
|
|
|
| 60 |
raw_documents = j.get("raw_documents")
|
| 61 |
outputs = j.get("outputs")
|
| 62 |
else:
|
| 63 |
response = f"Error: API status {resp.status_code}"
|
| 64 |
-
specs_advantages, raw_documents, outputs = None, None, None
|
| 65 |
except Exception as e:
|
| 66 |
response = f"Error calling API: {e}"
|
| 67 |
-
specs_advantages, raw_documents, outputs = None, None, None
|
| 68 |
|
| 69 |
end = time.perf_counter()
|
| 70 |
|
|
@@ -74,6 +78,8 @@ def respond_to_chat(message, history, state, selected_model, debug_mode):
|
|
| 74 |
# specs_advantages is now always a dict for both products and solutions
|
| 75 |
if isinstance(specs_advantages, dict):
|
| 76 |
state["specs_advantages"] = specs_advantages
|
|
|
|
|
|
|
| 77 |
state["raw_documents"] = raw_documents
|
| 78 |
state["outputs"] = outputs
|
| 79 |
|
|
@@ -236,22 +242,10 @@ def show_advantages(state, history=None):
|
|
| 236 |
|
| 237 |
def show_solution_packages(state, history=None):
|
| 238 |
"""Show solution packages in a structured format"""
|
| 239 |
-
|
| 240 |
if history is None:
|
| 241 |
history = []
|
| 242 |
|
| 243 |
-
if not specs_map:
|
| 244 |
-
# Fix: Use proper ChatInterface message format
|
| 245 |
-
history.append(
|
| 246 |
-
{"role": "assistant", "content": "馃摝 Kh么ng c贸 g贸i s岷 ph岷﹎ n脿o"})
|
| 247 |
-
return history
|
| 248 |
-
|
| 249 |
-
# Filter only solution packages
|
| 250 |
-
solution_packages = {}
|
| 251 |
-
for key, data in specs_map.items():
|
| 252 |
-
if data.get("model") == "G贸i gi岷 ph谩p":
|
| 253 |
-
solution_packages[key] = data
|
| 254 |
-
|
| 255 |
if not solution_packages:
|
| 256 |
# Fix: Use proper ChatInterface message format
|
| 257 |
history.append(
|
|
@@ -261,9 +255,9 @@ def show_solution_packages(state, history=None):
|
|
| 261 |
# Build markdown content for each package
|
| 262 |
markdown_content = "## 馃摝 G贸i s岷 ph岷﹎\n\n"
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
markdown_content +=
|
| 267 |
|
| 268 |
# Fix: Use proper ChatInterface message format
|
| 269 |
history.append({"role": "assistant", "content": markdown_content})
|
|
@@ -452,4 +446,4 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
| 452 |
)
|
| 453 |
|
| 454 |
if __name__ == "__main__":
|
| 455 |
-
demo.launch()
|
|
|
|
| 4 |
import time
|
| 5 |
import re
|
| 6 |
import os
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
load_dotenv()
|
| 9 |
|
| 10 |
+
# API_BASE_URL = os.getenv("API_BASE_URL")
|
| 11 |
API_BASE_URL = "https://sale-agent-m179.onrender.com"
|
| 12 |
|
| 13 |
|
|
|
|
| 60 |
j = resp.json()
|
| 61 |
response = j.get("response", "")
|
| 62 |
specs_advantages = j.get("specs_advantages")
|
| 63 |
+
solution_packages = j.get("solution_packages")
|
| 64 |
raw_documents = j.get("raw_documents")
|
| 65 |
outputs = j.get("outputs")
|
| 66 |
else:
|
| 67 |
response = f"Error: API status {resp.status_code}"
|
| 68 |
+
specs_advantages, solution_packages, raw_documents, outputs = None, None, None, None
|
| 69 |
except Exception as e:
|
| 70 |
response = f"Error calling API: {e}"
|
| 71 |
+
specs_advantages, solution_packages, raw_documents, outputs = None, None, None, None
|
| 72 |
|
| 73 |
end = time.perf_counter()
|
| 74 |
|
|
|
|
| 78 |
# specs_advantages is now always a dict for both products and solutions
|
| 79 |
if isinstance(specs_advantages, dict):
|
| 80 |
state["specs_advantages"] = specs_advantages
|
| 81 |
+
if solution_packages:
|
| 82 |
+
state["solution_packages"] = solution_packages
|
| 83 |
state["raw_documents"] = raw_documents
|
| 84 |
state["outputs"] = outputs
|
| 85 |
|
|
|
|
| 242 |
|
| 243 |
def show_solution_packages(state, history=None):
|
| 244 |
"""Show solution packages in a structured format"""
|
| 245 |
+
solution_packages = state.get("solution_packages", [])
|
| 246 |
if history is None:
|
| 247 |
history = []
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
if not solution_packages:
|
| 250 |
# Fix: Use proper ChatInterface message format
|
| 251 |
history.append(
|
|
|
|
| 255 |
# Build markdown content for each package
|
| 256 |
markdown_content = "## 馃摝 G贸i s岷 ph岷﹎\n\n"
|
| 257 |
|
| 258 |
+
# solution_packages is a list
|
| 259 |
+
for package in solution_packages:
|
| 260 |
+
markdown_content += f"{package}\n\n"
|
| 261 |
|
| 262 |
# Fix: Use proper ChatInterface message format
|
| 263 |
history.append({"role": "assistant", "content": markdown_content})
|
|
|
|
| 446 |
)
|
| 447 |
|
| 448 |
if __name__ == "__main__":
|
| 449 |
+
demo.launch()
|