Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -937,10 +937,12 @@ def side():
|
|
| 937 |
# Display the first matching trustbuilder
|
| 938 |
if matching_trustbuilders:
|
| 939 |
st.write("### Result:")
|
| 940 |
-
|
|
|
|
| 941 |
else:
|
| 942 |
st.write("No TrustBuilders found matching the criteria.")
|
| 943 |
|
|
|
|
| 944 |
|
| 945 |
# UI for saving TrustBuilders
|
| 946 |
st.subheader("Save TrustBuilders®")
|
|
@@ -1195,7 +1197,7 @@ tavily_tool = TavilySearchResults(
|
|
| 1195 |
max_results=10,
|
| 1196 |
search_depth="advanced",
|
| 1197 |
topic="news",
|
| 1198 |
-
days=
|
| 1199 |
include_answer=True,
|
| 1200 |
include_raw_content=True,
|
| 1201 |
# include_domains=[...],
|
|
@@ -1985,6 +1987,36 @@ if "handled" not in st.session_state:
|
|
| 1985 |
st.session_state["handled"] = False
|
| 1986 |
|
| 1987 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1988 |
prompt = st.chat_input("")
|
| 1989 |
global combined_text
|
| 1990 |
def handle_prompt(prompt):
|
|
@@ -2121,8 +2153,28 @@ def handle_prompt(prompt):
|
|
| 2121 |
display_typing_indicator()
|
| 2122 |
|
| 2123 |
cleaned_text = ""
|
| 2124 |
-
base_instructions = """
|
| 2125 |
-
Avoid Flowery language and ai words.Be over specific with numbers,names,dollars, programs ,awards and action*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2126 |
|
| 2127 |
1. **Adhere to Uploaded Document's Style**:
|
| 2128 |
- When asked uploaded files or document means knowledgebase.
|
|
@@ -2139,7 +2191,9 @@ def handle_prompt(prompt):
|
|
| 2139 |
4. **Ensure Accuracy**:
|
| 2140 |
- Provide only verifiable and accurate information. Do not include placeholders, fabricated URLs, or vague references.
|
| 2141 |
|
| 2142 |
-
|
|
|
|
|
|
|
| 2143 |
"""
|
| 2144 |
|
| 2145 |
|
|
@@ -2178,21 +2232,23 @@ def handle_prompt(prompt):
|
|
| 2178 |
})
|
| 2179 |
full_response = output["output"]
|
| 2180 |
|
| 2181 |
-
|
|
|
|
|
|
|
| 2182 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 2183 |
|
| 2184 |
|
| 2185 |
-
combined_text = f"{
|
| 2186 |
-
formatted_text = clean_and_format_markdown(combined_text)
|
| 2187 |
|
| 2188 |
with response_placeholder:
|
| 2189 |
with st.chat_message("assistant"):
|
| 2190 |
|
| 2191 |
-
st.
|
| 2192 |
|
| 2193 |
update_message_usage(st.session_state.get("wix_user_id", "default_user"))
|
| 2194 |
-
st.session_state.chat_history.append({"role": "assistant", "content":
|
| 2195 |
-
copy_to_clipboard(
|
| 2196 |
|
| 2197 |
except Exception as e:
|
| 2198 |
logging.error(f"Error generating response: {e}")
|
|
|
|
| 937 |
# Display the first matching trustbuilder
|
| 938 |
if matching_trustbuilders:
|
| 939 |
st.write("### Result:")
|
| 940 |
+
# Join the matching trustbuilders into a bullet list
|
| 941 |
+
st.markdown("\n".join([f"- {tb}" for tb in matching_trustbuilders]))
|
| 942 |
else:
|
| 943 |
st.write("No TrustBuilders found matching the criteria.")
|
| 944 |
|
| 945 |
+
|
| 946 |
|
| 947 |
# UI for saving TrustBuilders
|
| 948 |
st.subheader("Save TrustBuilders®")
|
|
|
|
| 1197 |
max_results=10,
|
| 1198 |
search_depth="advanced",
|
| 1199 |
topic="news",
|
| 1200 |
+
days=1,
|
| 1201 |
include_answer=True,
|
| 1202 |
include_raw_content=True,
|
| 1203 |
# include_domains=[...],
|
|
|
|
| 1987 |
st.session_state["handled"] = False
|
| 1988 |
|
| 1989 |
|
| 1990 |
+
|
| 1991 |
+
def clean_and_format_markdown(text: str) -> str:
|
| 1992 |
+
# Normalize Unicode
|
| 1993 |
+
text = unicodedata.normalize('NFKC', text)
|
| 1994 |
+
|
| 1995 |
+
# Remove zero-width and other invisible chars
|
| 1996 |
+
text = re.sub(r'[\u200B\uFEFF\u200C\u200D]', '', text)
|
| 1997 |
+
|
| 1998 |
+
# Remove control characters
|
| 1999 |
+
text = re.sub(r'[\x00-\x1F\x7F-\x9F]', '', text)
|
| 2000 |
+
|
| 2001 |
+
# Replace escaped and actual newlines with a single space
|
| 2002 |
+
text = text.replace('\\n', ' ').replace('\n', ' ')
|
| 2003 |
+
|
| 2004 |
+
# Remove HTML tags if any
|
| 2005 |
+
text = re.sub(r'<[^>]*>', '', text)
|
| 2006 |
+
|
| 2007 |
+
# Ensure space after punctuation if missing
|
| 2008 |
+
text = re.sub(r'([.,!?])(\S)', r'\1 \2', text)
|
| 2009 |
+
|
| 2010 |
+
# Ensure spacing between numbers and letters
|
| 2011 |
+
text = re.sub(r'(\d)([A-Za-z])', r'\1 \2', text)
|
| 2012 |
+
text = re.sub(r'([A-Za-z])(\d)', r'\1 \2', text)
|
| 2013 |
+
|
| 2014 |
+
# Normalize multiple spaces
|
| 2015 |
+
text = re.sub(r'\s+', ' ', text).strip()
|
| 2016 |
+
|
| 2017 |
+
return text
|
| 2018 |
+
|
| 2019 |
+
|
| 2020 |
prompt = st.chat_input("")
|
| 2021 |
global combined_text
|
| 2022 |
def handle_prompt(prompt):
|
|
|
|
| 2153 |
display_typing_indicator()
|
| 2154 |
|
| 2155 |
cleaned_text = ""
|
| 2156 |
+
# base_instructions = """
|
| 2157 |
+
# Avoid Flowery language and ai words.Be over specific with numbers,names,dollars, programs ,awards and action*
|
| 2158 |
+
|
| 2159 |
+
# 1. **Adhere to Uploaded Document's Style**:
|
| 2160 |
+
# - When asked uploaded files or document means knowledgebase.
|
| 2161 |
+
# - Use the uploaded document as a primary guide for writing style, tone, and structure. Just directly give response.
|
| 2162 |
+
# - Match formatting such as headings, subheadings, and paragraph styles. If the uploaded document lacks headings, Strictly do not include them in the response.
|
| 2163 |
+
|
| 2164 |
+
# 2. **Prioritize Knowledge Base and Internet Sources**:
|
| 2165 |
+
# - Use uploaded documents or knowledge base files as the primary source.
|
| 2166 |
+
# - Perform a Google search to retrieve valid and correct internet links for references, ensuring only accurate and verified source links are used.
|
| 2167 |
+
|
| 2168 |
+
# 3. **Avoid Flowery Language and AI Jargon**:
|
| 2169 |
+
# - Use clear, professional language without exaggerated or vague expressions. Avoid jargon like "beacon," "realm," "exemplifies," etc.
|
| 2170 |
+
|
| 2171 |
+
# 4. **Ensure Accuracy**:
|
| 2172 |
+
# - Provide only verifiable and accurate information. Do not include placeholders, fabricated URLs, or vague references.
|
| 2173 |
+
|
| 2174 |
+
|
| 2175 |
+
# """
|
| 2176 |
+
base_instructions="""
|
| 2177 |
+
Avoid Flowery language and ai words.Always include alof of data of numbers,names,dollars, programs ,awards and action when finding trustbuilders from internet.*
|
| 2178 |
|
| 2179 |
1. **Adhere to Uploaded Document's Style**:
|
| 2180 |
- When asked uploaded files or document means knowledgebase.
|
|
|
|
| 2191 |
4. **Ensure Accuracy**:
|
| 2192 |
- Provide only verifiable and accurate information. Do not include placeholders, fabricated URLs, or vague references.
|
| 2193 |
|
| 2194 |
+
- Give output in proper formatting.
|
| 2195 |
+
- Response in same language in which asked.
|
| 2196 |
+
-Use google to provide correct sources links containing the trustbuilder text information.
|
| 2197 |
"""
|
| 2198 |
|
| 2199 |
|
|
|
|
| 2232 |
})
|
| 2233 |
full_response = output["output"]
|
| 2234 |
|
| 2235 |
+
import html
|
| 2236 |
+
escaped_text = full_response.replace("$", "\$")
|
| 2237 |
+
|
| 2238 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 2239 |
|
| 2240 |
|
| 2241 |
+
combined_text = f"{escaped_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
|
| 2242 |
+
#formatted_text = clean_and_format_markdown(combined_text)
|
| 2243 |
|
| 2244 |
with response_placeholder:
|
| 2245 |
with st.chat_message("assistant"):
|
| 2246 |
|
| 2247 |
+
st.markdown(combined_text)
|
| 2248 |
|
| 2249 |
update_message_usage(st.session_state.get("wix_user_id", "default_user"))
|
| 2250 |
+
st.session_state.chat_history.append({"role": "assistant", "content": combined_text})
|
| 2251 |
+
copy_to_clipboard(combined_text)
|
| 2252 |
|
| 2253 |
except Exception as e:
|
| 2254 |
logging.error(f"Error generating response: {e}")
|