|
import streamlit as st |
|
import logging |
|
import asyncio |
|
from contextlib import asynccontextmanager |
|
from app import QueryRequest |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
st.set_page_config(page_title="Certification Chat", layout="centered") |
|
|
|
st.title("π Certification Chat Assistant") |
|
|
|
|
|
async def async_query(query_text): |
|
from app import handle_query |
|
request = QueryRequest(query=query_text) |
|
return await handle_query(request) |
|
|
|
|
|
def run_async(coroutine): |
|
try: |
|
loop = asyncio.get_event_loop() |
|
except RuntimeError: |
|
loop = asyncio.new_event_loop() |
|
asyncio.set_event_loop(loop) |
|
return loop.run_until_complete(coroutine) |
|
|
|
|
|
user_input = st.text_input("π¬ Enter your prompt:") |
|
|
|
if user_input: |
|
st.markdown("## π§ Response") |
|
|
|
try: |
|
|
|
with st.spinner("Processing your query..."): |
|
|
|
result = run_async(async_query(user_input)) |
|
|
|
|
|
st.write("**Certification:**", result["certification"]) |
|
st.write("**Answer from certif_index:**", result["certif_index"]) |
|
st.write("**Answer from certification_index:**", result["certification_index"]) |
|
|
|
except Exception as e: |
|
st.error(f"An error occurred: {str(e)}") |
|
logger.error(f"Error processing query: {e}", exc_info=True) |