Spaces:
Sleeping
Sleeping
WIP: Add latest trend functionality
Browse files- Gradio_UI.py +5 -1
- app.py +15 -36
Gradio_UI.py
CHANGED
|
@@ -262,7 +262,11 @@ class GradioUI:
|
|
| 262 |
import gradio as gr
|
| 263 |
|
| 264 |
with gr.Blocks(fill_height=True) as demo:
|
| 265 |
-
start_message =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
stored_messages = gr.State([gr.ChatMessage(role="assistant", content=start_message)])
|
| 267 |
file_uploads_log = gr.State([])
|
| 268 |
chatbot = gr.Chatbot(
|
|
|
|
| 262 |
import gradio as gr
|
| 263 |
|
| 264 |
with gr.Blocks(fill_height=True) as demo:
|
| 265 |
+
start_message = (
|
| 266 |
+
"Welcome to Trend Finder! To help you identify the most recent trends, please specify "
|
| 267 |
+
"the area or topic you are interested in. Enter your topic in Markdown format so that "
|
| 268 |
+
"it can be properly parsed and analyzed."
|
| 269 |
+
)
|
| 270 |
stored_messages = gr.State([gr.ChatMessage(role="assistant", content=start_message)])
|
| 271 |
file_uploads_log = gr.State([])
|
| 272 |
chatbot = gr.Chatbot(
|
app.py
CHANGED
|
@@ -12,51 +12,30 @@ from Gradio_UI import GradioUI
|
|
| 12 |
import re
|
| 13 |
from typing import Dict
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
@tool
|
| 16 |
def parse_search_results(query_results: str) -> Dict[str, str]:
|
| 17 |
"""
|
| 18 |
Parses search results text and extracts URLs along with their corresponding description.
|
| 19 |
|
| 20 |
Args:
|
| 21 |
-
query_results: A string representing the search results.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
Returns:
|
| 25 |
-
A dictionary where each key is a URL and
|
| 26 |
"""
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Split the input into lines
|
| 32 |
-
lines = query_results.splitlines()
|
| 33 |
-
print(lines)
|
| 34 |
-
|
| 35 |
-
# Regex pattern to match a URL (starting with http:// or https://)
|
| 36 |
-
url_pattern = re.compile(r"^(https?://\S+)")
|
| 37 |
-
|
| 38 |
-
for line in lines:
|
| 39 |
-
stripped_line = line.strip()
|
| 40 |
-
if not stripped_line:
|
| 41 |
-
continue # Skip empty lines
|
| 42 |
-
|
| 43 |
-
# Check if the line starts with a URL
|
| 44 |
-
url_match = url_pattern.match(stripped_line)
|
| 45 |
-
if url_match:
|
| 46 |
-
# Save the previous URL and its description if available
|
| 47 |
-
if current_url is not None:
|
| 48 |
-
results[current_url] = " ".join(current_desc).strip()
|
| 49 |
-
# Set the new URL and reset description accumulator
|
| 50 |
-
current_url = url_match.group(1)
|
| 51 |
-
current_desc = []
|
| 52 |
-
else:
|
| 53 |
-
# Accumulate description lines
|
| 54 |
-
current_desc.append(stripped_line)
|
| 55 |
-
|
| 56 |
-
# Save the last URL and its description if any
|
| 57 |
-
if current_url is not None:
|
| 58 |
-
results[current_url] = " ".join(current_desc).strip()
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return results
|
| 61 |
|
| 62 |
|
|
|
|
| 12 |
import re
|
| 13 |
from typing import Dict
|
| 14 |
|
| 15 |
+
import re
|
| 16 |
+
from typing import Dict
|
| 17 |
+
|
| 18 |
@tool
|
| 19 |
def parse_search_results(query_results: str) -> Dict[str, str]:
|
| 20 |
"""
|
| 21 |
Parses search results text and extracts URLs along with their corresponding description.
|
| 22 |
|
| 23 |
Args:
|
| 24 |
+
query_results: A string representing the search results.
|
| 25 |
+
Each result should start with a URL, followed by description text.
|
| 26 |
+
|
| 27 |
Returns:
|
| 28 |
+
A dictionary where each key is a URL and its value is the description text.
|
| 29 |
"""
|
| 30 |
+
# This regex matches a URL (starting with http:// or https://)
|
| 31 |
+
# followed by any text (including newlines) until the next URL or end of string.
|
| 32 |
+
pattern = re.compile(r"(https?://\S+)\s*([\s\S]*?)(?=(https?://\S+)|$)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
results = {}
|
| 35 |
+
for match in pattern.finditer(query_results):
|
| 36 |
+
url = match.group(1).strip()
|
| 37 |
+
description = match.group(2).strip()
|
| 38 |
+
results[url] = description
|
| 39 |
return results
|
| 40 |
|
| 41 |
|