Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1920,6 +1920,30 @@ user_name = extract_name(st.session_state["email"])
|
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1923 |
prompt = st.chat_input("")
|
| 1924 |
global combined_text
|
| 1925 |
def handle_prompt(prompt):
|
|
@@ -2014,7 +2038,7 @@ def handle_prompt(prompt):
|
|
| 2014 |
cleaned_text = ""
|
| 2015 |
base_instructions = (
|
| 2016 |
"Avoid flowery language, typical AI phrases, or jargon. "
|
| 2017 |
-
"Sources must be the latest, valid, and verifiable .Be specific with $amounts awards, people and programs."
|
| 2018 |
"Strictly dont use trustbucket names in copy headings and content avoid it"
|
| 2019 |
)
|
| 2020 |
|
|
|
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
+
|
| 1924 |
+
def clean_and_format_markdown(raw_text):
|
| 1925 |
+
"""
|
| 1926 |
+
Dynamically cleans and formats Markdown text to ensure URLs are properly encoded
|
| 1927 |
+
and handles issues with line breaks or improperly formatted Markdown.
|
| 1928 |
+
"""
|
| 1929 |
+
# Regular expression to find Markdown links [text](url)
|
| 1930 |
+
pattern = r'\[([^\]]+)\]\(([^)]+)\)'
|
| 1931 |
+
|
| 1932 |
+
def encode_url(match):
|
| 1933 |
+
text = match.group(1)
|
| 1934 |
+
url = match.group(2).strip() # Remove leading/trailing spaces
|
| 1935 |
+
encoded_url = quote(url, safe=':/') # Encode the URL while keeping : and /
|
| 1936 |
+
return f"[{text}]({encoded_url})"
|
| 1937 |
+
|
| 1938 |
+
# Fix Markdown links dynamically
|
| 1939 |
+
formatted_text = re.sub(pattern, encode_url, raw_text)
|
| 1940 |
+
|
| 1941 |
+
# Replace single newlines with spaces to avoid breaking Markdown rendering
|
| 1942 |
+
formatted_text = re.sub(r"(?<!\n)\n(?!\n)", " ", formatted_text)
|
| 1943 |
+
|
| 1944 |
+
return formatted_text
|
| 1945 |
+
|
| 1946 |
+
|
| 1947 |
prompt = st.chat_input("")
|
| 1948 |
global combined_text
|
| 1949 |
def handle_prompt(prompt):
|
|
|
|
| 2038 |
cleaned_text = ""
|
| 2039 |
base_instructions = (
|
| 2040 |
"Avoid flowery language, typical AI phrases, or jargon. "
|
| 2041 |
+
"Sources must be the latest, valid, and verifiable.Always give result on data present in knowledgebase when asked to use net or google then do.Be specific with $amounts awards, people and programs."
|
| 2042 |
"Strictly dont use trustbucket names in copy headings and content avoid it"
|
| 2043 |
)
|
| 2044 |
|