Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from get_prompts import get_prompt_for_mode
|
|
| 8 |
from dotenv import load_dotenv, set_key
|
| 9 |
from milvus import initialize_milvus, DEFAULT_MILVUS_HOST, DEFAULT_MILVUS_PORT, DEFAULT_COLLECTION_NAME, DEFAULT_DIMENSION, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY
|
| 10 |
from pymilvus import connections, MilvusException, utility
|
| 11 |
-
import markdown
|
| 12 |
|
| 13 |
# --- Configuration and Setup ---
|
| 14 |
|
|
@@ -206,28 +206,24 @@ def chat_ui(query, history, mode):
|
|
| 206 |
if response is None or not response.strip():
|
| 207 |
response = "An error occurred during processing. Please check the logs."
|
| 208 |
|
| 209 |
-
|
| 210 |
-
md = markdown.Markdown(extensions=['fenced_code'])
|
| 211 |
-
formatted_response = "" # Initialize formatted_response here
|
| 212 |
|
| 213 |
if mode == "developer":
|
| 214 |
extracted_files = extract_files_from_response(response)
|
| 215 |
-
|
| 216 |
-
# Iterate through the extracted files and format them
|
| 217 |
for filepath, content in extracted_files.items():
|
| 218 |
formatted_response += f"## {filepath}\n`\n{content}\n`\n\n"
|
| 219 |
-
|
| 220 |
-
# Remove the last extra newline characters if they exist
|
| 221 |
-
if formatted_response.endswith("\n\n"):
|
| 222 |
-
formatted_response = formatted_response[:-2]
|
| 223 |
else:
|
| 224 |
-
# Format the output for non-developer modes
|
| 225 |
formatted_response = response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
-
# Convert the entire response to HTML at once
|
| 228 |
-
formatted_response = md.convert(formatted_response)
|
| 229 |
history.append((query, formatted_response))
|
| 230 |
-
|
| 231 |
return history, history
|
| 232 |
# ZIP Processing Interface
|
| 233 |
zip_iface = gr.Interface(
|
|
|
|
| 8 |
from dotenv import load_dotenv, set_key
|
| 9 |
from milvus import initialize_milvus, DEFAULT_MILVUS_HOST, DEFAULT_MILVUS_PORT, DEFAULT_COLLECTION_NAME, DEFAULT_DIMENSION, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY
|
| 10 |
from pymilvus import connections, MilvusException, utility
|
| 11 |
+
import markdown
|
| 12 |
|
| 13 |
# --- Configuration and Setup ---
|
| 14 |
|
|
|
|
| 206 |
if response is None or not response.strip():
|
| 207 |
response = "An error occurred during processing. Please check the logs."
|
| 208 |
|
| 209 |
+
formatted_response = ""
|
|
|
|
|
|
|
| 210 |
|
| 211 |
if mode == "developer":
|
| 212 |
extracted_files = extract_files_from_response(response)
|
|
|
|
|
|
|
| 213 |
for filepath, content in extracted_files.items():
|
| 214 |
formatted_response += f"## {filepath}\n`\n{content}\n`\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
else:
|
|
|
|
| 216 |
formatted_response = response
|
| 217 |
+
|
| 218 |
+
# Use HTML directly for code blocks to preserve formatting
|
| 219 |
+
if mode == "developer":
|
| 220 |
+
formatted_response = formatted_response.replace("`\n", "<pre><code style=\"white-space: pre-wrap;\">").replace("\n`", "</code></pre>")
|
| 221 |
+
else:
|
| 222 |
+
# Convert the entire response to HTML at once
|
| 223 |
+
md = markdown.Markdown(extensions=['fenced_code'])
|
| 224 |
+
formatted_response = md.convert(formatted_response)
|
| 225 |
|
|
|
|
|
|
|
| 226 |
history.append((query, formatted_response))
|
|
|
|
| 227 |
return history, history
|
| 228 |
# ZIP Processing Interface
|
| 229 |
zip_iface = gr.Interface(
|