mirror of
https://github.com/fsecada01/Pygentic-AI.git
synced 2025-06-15 11:36:03 +00:00
WORKING: populating results
page.
This commit is contained in:
parent
f2363ff81d
commit
b11796ddd6
@ -1,5 +1,3 @@
|
||||
from pprint import pformat
|
||||
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup as soup
|
||||
from pydantic_ai import RunContext
|
||||
@ -119,10 +117,12 @@ async def run_agent(
|
||||
f"Perform a comprehensive SWOT analysis for this product: {url}",
|
||||
deps=deps,
|
||||
)
|
||||
logger.info(f"Agent Result: {pformat(result.data.model_dump())}")
|
||||
# logger.debug(f"Agent Result: {pformat(result.data.model_dump())}")
|
||||
|
||||
if deps.update_status_func:
|
||||
await deps.update_status_func(deps.request, "Analysis Complete")
|
||||
|
||||
return result.data
|
||||
except Exception as e:
|
||||
logger.exception(f"Error during agent run: {type(e), e, e.args}")
|
||||
|
||||
|
@ -84,17 +84,17 @@ async def get_status(request: Request):
|
||||
context = {"request": request, "messages": [], "result": False}
|
||||
session_id = request.session.get("analysis_id")
|
||||
if session_id:
|
||||
logger.info(f"Found session id! {session_id}")
|
||||
# logger.info(f"Found session id! {session_id}")
|
||||
messages = status_store.get(session_id, [])
|
||||
result = ANALYSIS_COMPLETE_MESSAGE in messages
|
||||
logger.info(
|
||||
f"Status check - Session ID: {session_id}, Messages: "
|
||||
f"{messages}",
|
||||
)
|
||||
# logger.info(
|
||||
# f"Status check - Session ID: {session_id}, Messages: "
|
||||
# f"{messages}",
|
||||
# )
|
||||
|
||||
context.update({"messages": messages, "result": result})
|
||||
|
||||
logger.info(context)
|
||||
# logger.info(context)
|
||||
|
||||
return templates.TemplateResponse("status.html", context=context)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import random
|
||||
import time
|
||||
from pprint import pformat
|
||||
from typing import Any
|
||||
|
||||
from loguru import logger
|
||||
@ -30,10 +31,14 @@ async def update_status(session_id: str, message: Any) -> None:
|
||||
:param message: Any
|
||||
:return: None
|
||||
"""
|
||||
logger.info(f"Updating status for session {session_id}: {message}")
|
||||
logger.debug(f"Updating status for session {session_id}: {message}")
|
||||
|
||||
# Handle SWOT analysis result
|
||||
if isinstance(message, SwotAnalysis):
|
||||
logger.info(f"SWOT analysis result for session {session_id}: {message}")
|
||||
logger.info(
|
||||
f"adding to the result store. Existing values: {result_store}"
|
||||
)
|
||||
result_store[session_id] = message.model_dump()
|
||||
status_store[session_id].append(ANALYSIS_COMPLETE_MESSAGE)
|
||||
return
|
||||
@ -79,6 +84,7 @@ async def run_agent_with_progress(session_id, url):
|
||||
|
||||
if not isinstance(result, Exception):
|
||||
logger.info(f"Successfully analyzed URL: {url}")
|
||||
logger.debug(pformat(f"Result object: {result}"))
|
||||
result_store[session_id] = result
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
|
@ -5,7 +5,6 @@ target: str,
|
||||
method: str = 'GET',
|
||||
trigger: str = 'submit'
|
||||
#}
|
||||
<div class="container">
|
||||
<form id="{{ form_id }}"
|
||||
{% if method.lower()=='get' %}
|
||||
hx-get="{{ action }}"
|
||||
@ -20,4 +19,3 @@ trigger: str = 'submit'
|
||||
hx-target="#{{ target }}">
|
||||
{{ content }}
|
||||
</form>
|
||||
</div>
|
@ -1,22 +1,21 @@
|
||||
{# def
|
||||
form_id: str,
|
||||
action: str,
|
||||
target: str,
|
||||
method: str = 'GET'
|
||||
input_name: str = 'url',
|
||||
label: bool = False,
|
||||
label_name: str = 'Search',
|
||||
input_type: str = 'text',
|
||||
class_name: str = 'input is-rounded',
|
||||
placeholder: str = 'URL'
|
||||
#}
|
||||
<Form form_id={{ form_id }}
|
||||
action={{ action }}
|
||||
target={{ target }}
|
||||
method={{ method }}>
|
||||
<div class="control">
|
||||
<label for="url"
|
||||
class="label">Search</label>
|
||||
<input type="url"
|
||||
class="input is-rounded"
|
||||
id="url"
|
||||
name="url"
|
||||
placeholder="URL"
|
||||
<div class="control is-expanded">
|
||||
{% if label %}
|
||||
<label for={{ input_name }}
|
||||
class="label">{{ label_name }}</label>
|
||||
{% endif %}
|
||||
<input type={{ input_type }}
|
||||
class={{ class_name }}
|
||||
id={{ input_name }}
|
||||
name={{ input_name }}
|
||||
placeholder={{ placeholder }}
|
||||
required />
|
||||
</div>
|
||||
{{ content }}
|
||||
</Form>
|
@ -2,7 +2,7 @@
|
||||
result,
|
||||
#}
|
||||
|
||||
<li>
|
||||
<li class='m-2 p-2'>
|
||||
<span class='icon'>
|
||||
{{ content }}
|
||||
</span>
|
||||
|
@ -12,11 +12,12 @@
|
||||
<Spinner></Spinner>
|
||||
<div class="container">
|
||||
<h1 class="title">Search Here</h1>
|
||||
<Search form_id="swotSearch"
|
||||
<Form form_id="swotSearch"
|
||||
action={{ url_for('analyze_url') }}
|
||||
target="status"
|
||||
method="post">
|
||||
<div class="field mt-1 pt-1">
|
||||
<div class="field has-addons">
|
||||
<Search input_type='url'>
|
||||
<div class="control">
|
||||
<button type="submit"
|
||||
class="button is-success"
|
||||
@ -27,8 +28,9 @@
|
||||
result.style.display = 'none';
|
||||
">Analyze</button>
|
||||
</div>
|
||||
</div>
|
||||
</Search>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section"
|
||||
|
@ -1,34 +1,39 @@
|
||||
{% if result %}
|
||||
<section class="section"
|
||||
id="result-container">
|
||||
<h2 class="title is-2">
|
||||
{{ result }}
|
||||
</h2>
|
||||
<div class="container">
|
||||
<h2 class="subtitle is-2">Analysis Complete</h2>
|
||||
<div class="fixed-grid">
|
||||
<div class="fixed-grid has-2-cols">
|
||||
<div class="grid">
|
||||
{% for cat, val in result.items() %}
|
||||
{% for cat, val in result.dict().items() %}
|
||||
{% if not loop.last %}
|
||||
<div class="cell">
|
||||
<div class="content">
|
||||
{% set panel_class = 'success' if cat == 'strengths' else ('warning' if cat == 'weaknesses' else ('info' if cat == 'opportunities' else 'danger')) %}
|
||||
{% set i_class = 'fas fa-solid fa-arrow-up' if cat == 'strengths' else ('fas fa-solid fa-arrow-down' if cat == 'weaknesses' else ('fas fa-regular fa-lightbulb' if cat == 'opportunities' else 'fas fa-solid fa-triangle-exclamation')) %}
|
||||
<div class="panel is-{{ panel_class }}">
|
||||
<p class="panel-heading">{{ cat.title() }}</p>
|
||||
<div class="panel-block">
|
||||
<ul>
|
||||
{% for value in val %}
|
||||
<ResultEntry result=value>
|
||||
{% if cat == 'strengths' %}
|
||||
<i class="fas fa-solid fa-arrow-up"></i>
|
||||
{% elif cat == 'weaknesses' %}
|
||||
<i class="fas fa-solid fa-arrow-down"></i>
|
||||
{% elif cat == 'opportunities' %}
|
||||
<i class="fas fa-regular fa-lightbulb"></i>
|
||||
{% else %}
|
||||
<i
|
||||
class="fas fa-solid fa-triangle-exclamation"></i>
|
||||
{% endif %}
|
||||
<ResultEntry result={{ value }}>
|
||||
<i class="{{ i_class }}"></i>
|
||||
</ResultEntry>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="cell is-col-span-2">
|
||||
<div class="panel is-primary m-2 p-2">
|
||||
<p class="panel-heading">{{ cat.title() }}</p>
|
||||
<div
|
||||
class="panel-block has-text-justified has-text-weight-light">
|
||||
{{ val }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user