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
|
import httpx
|
||||||
from bs4 import BeautifulSoup as soup
|
from bs4 import BeautifulSoup as soup
|
||||||
from pydantic_ai import RunContext
|
from pydantic_ai import RunContext
|
||||||
@ -119,10 +117,12 @@ async def run_agent(
|
|||||||
f"Perform a comprehensive SWOT analysis for this product: {url}",
|
f"Perform a comprehensive SWOT analysis for this product: {url}",
|
||||||
deps=deps,
|
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:
|
if deps.update_status_func:
|
||||||
await deps.update_status_func(deps.request, "Analysis Complete")
|
await deps.update_status_func(deps.request, "Analysis Complete")
|
||||||
|
|
||||||
|
return result.data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error during agent run: {type(e), e, e.args}")
|
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}
|
context = {"request": request, "messages": [], "result": False}
|
||||||
session_id = request.session.get("analysis_id")
|
session_id = request.session.get("analysis_id")
|
||||||
if session_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, [])
|
messages = status_store.get(session_id, [])
|
||||||
result = ANALYSIS_COMPLETE_MESSAGE in messages
|
result = ANALYSIS_COMPLETE_MESSAGE in messages
|
||||||
logger.info(
|
# logger.info(
|
||||||
f"Status check - Session ID: {session_id}, Messages: "
|
# f"Status check - Session ID: {session_id}, Messages: "
|
||||||
f"{messages}",
|
# f"{messages}",
|
||||||
)
|
# )
|
||||||
|
|
||||||
context.update({"messages": messages, "result": result})
|
context.update({"messages": messages, "result": result})
|
||||||
|
|
||||||
logger.info(context)
|
# logger.info(context)
|
||||||
|
|
||||||
return templates.TemplateResponse("status.html", context=context)
|
return templates.TemplateResponse("status.html", context=context)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
from pprint import pformat
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@ -30,10 +31,14 @@ async def update_status(session_id: str, message: Any) -> None:
|
|||||||
:param message: Any
|
:param message: Any
|
||||||
:return: None
|
: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
|
# Handle SWOT analysis result
|
||||||
if isinstance(message, SwotAnalysis):
|
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()
|
result_store[session_id] = message.model_dump()
|
||||||
status_store[session_id].append(ANALYSIS_COMPLETE_MESSAGE)
|
status_store[session_id].append(ANALYSIS_COMPLETE_MESSAGE)
|
||||||
return
|
return
|
||||||
@ -79,6 +84,7 @@ async def run_agent_with_progress(session_id, url):
|
|||||||
|
|
||||||
if not isinstance(result, Exception):
|
if not isinstance(result, Exception):
|
||||||
logger.info(f"Successfully analyzed URL: {url}")
|
logger.info(f"Successfully analyzed URL: {url}")
|
||||||
|
logger.debug(pformat(f"Result object: {result}"))
|
||||||
result_store[session_id] = result
|
result_store[session_id] = result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -5,19 +5,17 @@ target: str,
|
|||||||
method: str = 'GET',
|
method: str = 'GET',
|
||||||
trigger: str = 'submit'
|
trigger: str = 'submit'
|
||||||
#}
|
#}
|
||||||
<div class="container">
|
<form id="{{ form_id }}"
|
||||||
<form id="{{ form_id }}"
|
{% if method.lower()=='get' %}
|
||||||
{% if method.lower() == 'get' %}
|
hx-get="{{ action }}"
|
||||||
hx-get="{{ action }}"
|
{% elif method.lower()=='post' %}
|
||||||
{% elif method.lower() == 'post' %}
|
hx-post="{{ action }}"
|
||||||
hx-post="{{ action }}"
|
{% elif method.lower()=='put' %}
|
||||||
{% elif method.lower() == 'put' %}
|
hx-put="{{ action }}"
|
||||||
hx-put="{{ action }}"
|
{% elif method.lower()=='delete' %}
|
||||||
{% elif method.lower() == 'delete' %}
|
hx-delete="{{ action }}"
|
||||||
hx-delete="{{ action }}"
|
{% endif %}
|
||||||
{% endif %}
|
hx-trigger="{{ trigger }}"
|
||||||
hx-trigger="{{ trigger }}"
|
hx-target="#{{ target }}">
|
||||||
hx-target="#{{ target }}">
|
{{ content }}
|
||||||
{{ content }}
|
</form>
|
||||||
</form>
|
|
||||||
</div>
|
|
@ -1,22 +1,21 @@
|
|||||||
{# def
|
{# def
|
||||||
form_id: str,
|
input_name: str = 'url',
|
||||||
action: str,
|
label: bool = False,
|
||||||
target: str,
|
label_name: str = 'Search',
|
||||||
method: str = 'GET'
|
input_type: str = 'text',
|
||||||
|
class_name: str = 'input is-rounded',
|
||||||
|
placeholder: str = 'URL'
|
||||||
#}
|
#}
|
||||||
<Form form_id={{ form_id }}
|
<div class="control is-expanded">
|
||||||
action={{ action }}
|
{% if label %}
|
||||||
target={{ target }}
|
<label for={{ input_name }}
|
||||||
method={{ method }}>
|
class="label">{{ label_name }}</label>
|
||||||
<div class="control">
|
{% endif %}
|
||||||
<label for="url"
|
<input type={{ input_type }}
|
||||||
class="label">Search</label>
|
class={{ class_name }}
|
||||||
<input type="url"
|
id={{ input_name }}
|
||||||
class="input is-rounded"
|
name={{ input_name }}
|
||||||
id="url"
|
placeholder={{ placeholder }}
|
||||||
name="url"
|
required />
|
||||||
placeholder="URL"
|
</div>
|
||||||
required />
|
{{ content }}
|
||||||
</div>
|
|
||||||
{{ content }}
|
|
||||||
</Form>
|
|
@ -2,7 +2,7 @@
|
|||||||
result,
|
result,
|
||||||
#}
|
#}
|
||||||
|
|
||||||
<li>
|
<li class='m-2 p-2'>
|
||||||
<span class='icon'>
|
<span class='icon'>
|
||||||
{{ content }}
|
{{ content }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -12,23 +12,25 @@
|
|||||||
<Spinner></Spinner>
|
<Spinner></Spinner>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title">Search Here</h1>
|
<h1 class="title">Search Here</h1>
|
||||||
<Search form_id="swotSearch"
|
<Form form_id="swotSearch"
|
||||||
action={{ url_for('analyze_url') }}
|
action={{ url_for('analyze_url') }}
|
||||||
target="status"
|
target="status"
|
||||||
method="post">
|
method="post">
|
||||||
<div class="field mt-1 pt-1">
|
<div class="field has-addons">
|
||||||
<div class="control">
|
<Search input_type='url'>
|
||||||
<button type="submit"
|
<div class="control">
|
||||||
class="button is-success"
|
<button type="submit"
|
||||||
hx-indicator='#spinner'
|
class="button is-success"
|
||||||
hx-on:click="
|
hx-indicator='#spinner'
|
||||||
const [status, result] = ['#status', '#result'].map(id => document.querySelector(id));
|
hx-on:click="
|
||||||
status.style.display = 'block';
|
const [status, result] = ['#status', '#result'].map(id => document.querySelector(id));
|
||||||
result.style.display = 'none';
|
status.style.display = 'block';
|
||||||
">Analyze</button>
|
result.style.display = 'none';
|
||||||
</div>
|
">Analyze</button>
|
||||||
</div>
|
</div>
|
||||||
</Search>
|
</Search>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="section"
|
<section class="section"
|
||||||
@ -47,7 +49,7 @@
|
|||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
hx-on:after-request="
|
hx-on:after-request="
|
||||||
if(this.innerHTML.trim().length > 0) {
|
if(this.innerHTML.trim().length > 0) {
|
||||||
console.log('Going to turn off the status element and load the result element.')
|
console.log('Going to turn off the status element and load the result element.')
|
||||||
const statusDiv = document.querySelector('#status');
|
const statusDiv = document.querySelector('#status');
|
||||||
if (statusDiv) statusDiv.style.display = 'none';
|
if (statusDiv) statusDiv.style.display = 'none';
|
||||||
this.style.display = 'block'
|
this.style.display = 'block'
|
||||||
|
@ -1,34 +1,39 @@
|
|||||||
{% if result %}
|
{% if result %}
|
||||||
<section class="section"
|
<section class="section"
|
||||||
id="result-container">
|
id="result-container">
|
||||||
<h2 class="title is-2">
|
|
||||||
{{ result }}
|
|
||||||
</h2>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 class="subtitle is-2">Analysis Complete</h2>
|
<h2 class="subtitle is-2">Analysis Complete</h2>
|
||||||
<div class="fixed-grid">
|
<div class="fixed-grid has-2-cols">
|
||||||
<div class="grid">
|
<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="cell">
|
||||||
<div class="content">
|
{% set panel_class = 'success' if cat == 'strengths' else ('warning' if cat == 'weaknesses' else ('info' if cat == 'opportunities' else 'danger')) %}
|
||||||
<ul>
|
{% 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')) %}
|
||||||
{% for value in val %}
|
<div class="panel is-{{ panel_class }}">
|
||||||
<ResultEntry result=value>
|
<p class="panel-heading">{{ cat.title() }}</p>
|
||||||
{% if cat == 'strengths' %}
|
<div class="panel-block">
|
||||||
<i class="fas fa-solid fa-arrow-up"></i>
|
<ul>
|
||||||
{% elif cat == 'weaknesses' %}
|
{% for value in val %}
|
||||||
<i class="fas fa-solid fa-arrow-down"></i>
|
<ResultEntry result={{ value }}>
|
||||||
{% elif cat == 'opportunities' %}
|
<i class="{{ i_class }}"></i>
|
||||||
<i class="fas fa-regular fa-lightbulb"></i>
|
</ResultEntry>
|
||||||
{% else %}
|
{% endfor %}
|
||||||
<i
|
</ul>
|
||||||
class="fas fa-solid fa-triangle-exclamation"></i>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</ResultEntry>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user