Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,25 +71,18 @@ and output only the code
|
|
| 71 |
)
|
| 72 |
return call_visual_llm(prompt)
|
| 73 |
|
| 74 |
-
def replace_visual_placeholders(report_html: str, context:str, initial_query:str, crumbs:str) -> str:
|
| 75 |
-
""
|
| 76 |
-
|
| 77 |
-
Placeholders are expected to have the form:
|
| 78 |
-
|
| 79 |
-
[[Visual Placeholder X: Purpose: <description>]]
|
| 80 |
-
|
| 81 |
-
Returns the modified HTML.
|
| 82 |
-
"""
|
| 83 |
-
# This regex matches the placeholder and extracts the description after "Purpose:"
|
| 84 |
-
pattern = r"\[\[Visual Placeholder.*?\]\]"
|
| 85 |
-
|
| 86 |
def placeholder_replacer(match):
|
| 87 |
-
placeholder_instructions = match.group(1).strip()
|
| 88 |
logging.info(f"Generating visual for placeholder: {placeholder_instructions}")
|
|
|
|
| 89 |
# Call the visual generation function:
|
| 90 |
visual_html = generate_visual_snippet(placeholder_instructions, context, initial_query, crumbs)
|
| 91 |
return visual_html
|
| 92 |
|
|
|
|
| 93 |
new_report_html = re.sub(pattern, placeholder_replacer, report_html, flags=re.DOTALL)
|
| 94 |
return new_report_html
|
| 95 |
|
|
@@ -255,7 +248,8 @@ def perform_serpapi_search(query: str, engine: str, num_results: int = 10) -> li
|
|
| 255 |
results = []
|
| 256 |
while attempt < 3:
|
| 257 |
try:
|
| 258 |
-
|
|
|
|
| 259 |
if response.status_code == 200:
|
| 260 |
try:
|
| 261 |
data = response.json()
|
|
@@ -288,7 +282,8 @@ def perform_serpapi_search(query: str, engine: str, num_results: int = 10) -> li
|
|
| 288 |
|
| 289 |
def process_pdf(url: str) -> str:
|
| 290 |
try:
|
| 291 |
-
|
|
|
|
| 292 |
r.raise_for_status()
|
| 293 |
f = io.BytesIO(r.content)
|
| 294 |
reader = PyPDF2.PdfReader(f)
|
|
@@ -340,7 +335,11 @@ The report should be very detailed and lengthy — approximately the equivalent
|
|
| 340 |
|
| 341 |
// Special analytical artefacts.
|
| 342 |
- Since the generation of visuals (excluding tables) like graph or charts cannot be done through text, create special placeholders in this format:
|
| 343 |
-
[[Visual Placeholder n:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
with n as the reference number
|
| 345 |
- in the placeholder, no need to add the references to the source, but make sure ALL of the data pointes required has a source from the learning and reference material hereafter
|
| 346 |
- these placeholders text should contain:
|
|
@@ -814,7 +813,8 @@ def iterative_deep_research_gen(initial_query: str, reportstyle: str, breadth: i
|
|
| 814 |
process_log += f"Extracted PDF content from {url}\n"
|
| 815 |
else:
|
| 816 |
try:
|
| 817 |
-
|
|
|
|
| 818 |
response.raise_for_status()
|
| 819 |
raw_content = response.text
|
| 820 |
process_log += f"Extracted full page content from {url}\n"
|
|
|
|
| 71 |
)
|
| 72 |
return call_visual_llm(prompt)
|
| 73 |
|
| 74 |
+
def replace_visual_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 75 |
+
pattern = r"\[\[Visual Placeholder \d+:(.*?)\]\]" # Regex to match placeholders
|
| 76 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def placeholder_replacer(match):
|
| 78 |
+
placeholder_instructions = match.group(1).strip() # Extract and strip placeholder instructions
|
| 79 |
logging.info(f"Generating visual for placeholder: {placeholder_instructions}")
|
| 80 |
+
|
| 81 |
# Call the visual generation function:
|
| 82 |
visual_html = generate_visual_snippet(placeholder_instructions, context, initial_query, crumbs)
|
| 83 |
return visual_html
|
| 84 |
|
| 85 |
+
# Replace all matches in the HTML
|
| 86 |
new_report_html = re.sub(pattern, placeholder_replacer, report_html, flags=re.DOTALL)
|
| 87 |
return new_report_html
|
| 88 |
|
|
|
|
| 248 |
results = []
|
| 249 |
while attempt < 3:
|
| 250 |
try:
|
| 251 |
+
headers = {"User-Agent": get_random_header()}
|
| 252 |
+
response = requests.get("https://serpapi.com/search", params=params, headers=headers)
|
| 253 |
if response.status_code == 200:
|
| 254 |
try:
|
| 255 |
data = response.json()
|
|
|
|
| 282 |
|
| 283 |
def process_pdf(url: str) -> str:
|
| 284 |
try:
|
| 285 |
+
headers = {"User-Agent": get_random_header()}
|
| 286 |
+
response = requests.get("https://serpapi.com/search", params=params, headers=headers)
|
| 287 |
r.raise_for_status()
|
| 288 |
f = io.BytesIO(r.content)
|
| 289 |
reader = PyPDF2.PdfReader(f)
|
|
|
|
| 335 |
|
| 336 |
// Special analytical artefacts.
|
| 337 |
- Since the generation of visuals (excluding tables) like graph or charts cannot be done through text, create special placeholders in this format:
|
| 338 |
+
[[Visual Placeholder n:
|
| 339 |
+
- Purpose of this visual is:...
|
| 340 |
+
- Relevant data to generate it:...
|
| 341 |
+
- Visual guidance:...
|
| 342 |
+
]]
|
| 343 |
with n as the reference number
|
| 344 |
- in the placeholder, no need to add the references to the source, but make sure ALL of the data pointes required has a source from the learning and reference material hereafter
|
| 345 |
- these placeholders text should contain:
|
|
|
|
| 813 |
process_log += f"Extracted PDF content from {url}\n"
|
| 814 |
else:
|
| 815 |
try:
|
| 816 |
+
headers = {"User-Agent": get_random_header()}
|
| 817 |
+
response = requests.get("https://serpapi.com/search", params=params, headers=headers)
|
| 818 |
response.raise_for_status()
|
| 819 |
raw_content = response.text
|
| 820 |
process_log += f"Extracted full page content from {url}\n"
|