Spaces:
Sleeping
Sleeping
File size: 3,851 Bytes
36c187e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
from openai import OpenAI
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_openai.embeddings import OpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
import markdown
from operator import itemgetter
from langchain.schema.runnable import RunnablePassthrough
from langchain_core.prompts import ChatPromptTemplate
from langchain.schema import Document
from dotenv import load_dotenv
from langchain_community.vectorstores import Qdrant
#from langchain_qdrant import Qdrant
import os
import pandas as pd
import numpy as np
import datetime
# Page config
from PIL import Image, ImageEnhance
st.set_page_config(
page_title="Narrativ π°",
layout="wide",
initial_sidebar_state="expanded",
page_icon="π",
)
# Load environment variables
load_dotenv()
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
base_llm = ChatOpenAI(model="gpt-4o")
embedding_model = OpenAIEmbeddings(model="text-embedding-3-small")
prompt='I-495'
date='2025-01-15'
# Custom CSS for centered content
st.markdown("""
<style>
.main-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.stSelectbox {
max-width: 400px;
margin: 0 auto;
}
/* Center all text elements */
.centered-text {
text-align: center;
}
</style>
""", unsafe_allow_html=True)
# Header
col1, col2, col3, col4,col5 = st.columns([1, 1, 2, 1, 1])
with col3:
st.markdown("<h1 class='centered-text'>Search Narrativ</h1>", unsafe_allow_html=True)
with col4:
image = Image.open('./data/news_icon.png')
st.image(image, width=100, output_format="PNG", clamp=True)
st.markdown("<p class='centered-text'>Enter a topic and optional date to analyze traffic.</p>", unsafe_allow_html=True)
# Suggestions
topic_suggestions = [
"I-495",
"I-95",
"accident"
]
data=pd.read_csv('./data/sentiment_index_traffic_index_final1.csv',
index_col='index',
parse_dates=True
)
# Convert the index to datetime, if not already done
data.index = pd.to_datetime(data.index)
# Generate a sorted list of unique dates
sorted_dates = sorted(pd.unique(data.index))
# Format the sorted dates as string 'YYYY-MM-DD'
date_suggestions = [pd.Timestamp(date).strftime('%Y-%m-%d') for date in sorted_dates]
date_suggestions=np.append('',date_suggestions)
# Create centered container for search
# Define the allowed date range
start_date = datetime.date(2025, 1, 15)
end_date = datetime.date(2025, 1, 21)
col1, col2= st.columns([1,1])
with col1:
prompt = st.selectbox(
"Topic:",
options=[""] + topic_suggestions,
index=0,
key="topic_select",
placeholder="Select or type a topic..."
)
with col2:
# date =
#st.date_input(
# "Choose a date:",
# # min_value=start_date,
# # max_value=end_date,
# # value=start_date # Default to start date
# )
date = st.selectbox(
"Date (optional):",
options=date_suggestions,
index=0,
key="date_select",
placeholder="Select or type a date..."
)
date=str(date)
# st.write(f"You selected: {date} for the topic: {prompt}.")
col1, col2, col3, col4 = st.columns([1,1,1,1])
with col2:
chat = st.button("chat", key="chat_button", use_container_width=True)
with col3:
tableau=st.button("tableau", key="tableau_button", use_container_width=True)
# Handle search submission
st.session_state.prompt = prompt
st.session_state.date = date
if chat:
# You can add navigation to results page or display results here
st.success(f"Searching for: {prompt} {'on ' + date if date else ''}")
# Add your search processing logic here
st.switch_page("./pages/chat.py")
if tableau:
st.switch_page("./pages/tableau.py")
|