Guiyom commited on
Commit
d2d2c24
·
verified ·
1 Parent(s): d253a12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -1,7 +1,7 @@
1
  # =============================================================================
2
  # By T.Sakai / G.Huet
3
  # =============================================================================
4
- import os, time, io, json, random, re, requests, openai, base64
5
  import gradio as gr
6
  import PyPDF2, tempfile, logging, difflib
7
  import markdown, unicodedata, pdfkit
@@ -829,6 +829,9 @@ def expand_snippet_area(soup: BeautifulSoup, snippet: str) -> Tag:
829
  def fine_tune_report(adjustment_request: str, openai_api_key: str, serpapi_api_key: str, report_html: str,
830
  initial_request: str, qa: str, target_style: str, knowledge_crumbs: str,
831
  complementary_guidance: str) -> (str, str):
 
 
 
832
  # Quick adjustments
833
  if "remove the following text:" in adjustment_request.lower():
834
  # Extract the target text and process removal directly.
@@ -1052,6 +1055,8 @@ Now provide your suggestions."""
1052
  def improve_report_from_chat(user_message: str, chat_history: list, report_text: str, crumbs_text: str, style: str, initial_request: str, qa: str, complementary_guidance: str):
1053
  adjustment_request = user_message.replace("@improve", "").strip()
1054
 
 
 
1055
  # --- CASE 1: Removal request ---
1056
  removal_match = re.search(r"remove the following text:\s*\[\[([^\]]+)\]\]", adjustment_request, re.I)
1057
  if removal_match:
@@ -1115,6 +1120,9 @@ def expand_report(expansion_request: str, openai_api_key: str, serpapi_api_key:
1115
  os.environ["OPENAI_API_KEY"] = openai_api_key
1116
  os.environ["SERPAPI_API_KEY"] = serpapi_api_key
1117
 
 
 
 
1118
  logging.info("expansion_report: Starting fine-tuning process based on the adjustment request.")
1119
 
1120
  # Step 1: Identify unique strings in the targeted sections.
@@ -1320,6 +1328,10 @@ def expand_report_from_chat(user_message: str, chat_history: list, report_text:
1320
  Then, use those suggestions (if any) as the expansion instruction to update the report HTML.
1321
  Returns the updated chat history and the updated report.
1322
  """
 
 
 
 
1323
  expand_request = user_message.replace("@expand", "").strip()
1324
 
1325
  suggestions = suggest_expansions(report_text, os.getenv("OPENAI_API_KEY"), os.getenv("SERPAPI_API_KEY"),
@@ -1395,6 +1407,8 @@ Now provide your suggestions to expand the report."""
1395
  def send_chat_message(user_message, openai_api_key, serpapi_api_key, chat_history, report_text, crumbs_text, style, initial_request, qa, complementary_guidance):
1396
  os.environ["OPENAI_API_KEY"] = openai_api_key
1397
  os.environ["SERPAPI_API_KEY"] = serpapi_api_key
 
 
1398
 
1399
  if "@improve" in user_message.lower():
1400
  return improve_report_from_chat(user_message, chat_history, report_text, crumbs_text, style, initial_request, qa, complementary_guidance)
 
1
  # =============================================================================
2
  # By T.Sakai / G.Huet
3
  # =============================================================================
4
+ import os, time, io, json, random, re, requests, openai, base64, html
5
  import gradio as gr
6
  import PyPDF2, tempfile, logging, difflib
7
  import markdown, unicodedata, pdfkit
 
829
  def fine_tune_report(adjustment_request: str, openai_api_key: str, serpapi_api_key: str, report_html: str,
830
  initial_request: str, qa: str, target_style: str, knowledge_crumbs: str,
831
  complementary_guidance: str) -> (str, str):
832
+ # unescape report
833
+ report_html = html.unescape(report_html)
834
+
835
  # Quick adjustments
836
  if "remove the following text:" in adjustment_request.lower():
837
  # Extract the target text and process removal directly.
 
1055
  def improve_report_from_chat(user_message: str, chat_history: list, report_text: str, crumbs_text: str, style: str, initial_request: str, qa: str, complementary_guidance: str):
1056
  adjustment_request = user_message.replace("@improve", "").strip()
1057
 
1058
+ report_text = html.unescape(report_text)
1059
+
1060
  # --- CASE 1: Removal request ---
1061
  removal_match = re.search(r"remove the following text:\s*\[\[([^\]]+)\]\]", adjustment_request, re.I)
1062
  if removal_match:
 
1120
  os.environ["OPENAI_API_KEY"] = openai_api_key
1121
  os.environ["SERPAPI_API_KEY"] = serpapi_api_key
1122
 
1123
+ # unescape report
1124
+ report_html = html.unescape(report_html)
1125
+
1126
  logging.info("expansion_report: Starting fine-tuning process based on the adjustment request.")
1127
 
1128
  # Step 1: Identify unique strings in the targeted sections.
 
1328
  Then, use those suggestions (if any) as the expansion instruction to update the report HTML.
1329
  Returns the updated chat history and the updated report.
1330
  """
1331
+
1332
+ # unescape report
1333
+ report_text = html.unescape(report_text)
1334
+
1335
  expand_request = user_message.replace("@expand", "").strip()
1336
 
1337
  suggestions = suggest_expansions(report_text, os.getenv("OPENAI_API_KEY"), os.getenv("SERPAPI_API_KEY"),
 
1407
  def send_chat_message(user_message, openai_api_key, serpapi_api_key, chat_history, report_text, crumbs_text, style, initial_request, qa, complementary_guidance):
1408
  os.environ["OPENAI_API_KEY"] = openai_api_key
1409
  os.environ["SERPAPI_API_KEY"] = serpapi_api_key
1410
+
1411
+ report_text = html.unescape(report_text)
1412
 
1413
  if "@improve" in user_message.lower():
1414
  return improve_report_from_chat(user_message, chat_history, report_text, crumbs_text, style, initial_request, qa, complementary_guidance)