text
stringlengths
1
93.6k
show_pdf_preview(uploaded_file)
except Exception as error:
st.error(f"An error occurred: {error}")
st.stop()
column1, column2 = st.columns([6, 1])
with column1:
st.header("Docling with Ollama")
with column2:
st.button("Clear ↺", on_click=clear_chat_history)
if "chat_messages" not in st.session_state:
clear_chat_history()
for message in st.session_state.chat_messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if user_input := st.chat_input("Hi There?"):
st.session_state.chat_messages.append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
with st.chat_message("assistant"):
message_display = st.empty()
response_accum = ""
streaming_response = query_engine.query(user_input)
for part in streaming_response.response_gen:
response_accum += part
message_display.markdown(response_accum + "▌")
message_display.markdown(response_accum)
st.session_state.chat_messages.append({"role": "assistant", "content": response_accum})
# <FILESEP>
#!/usr/bin/env python
import numpy as np
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, SUPPRESS
import pandas as pd
import matplotlib.pyplot as plt
import os
import datetime as dt
from tools import convert_currency, extract_hierarchical_info, compute_risk
from models import *
from download import download, get_exchange_rates
from volatile import rate, estimate_logprice_statistics, estimate_price_statistics
from bots import *
if __name__ == '__main__':
today = dt.date.today().strftime("%Y-%m-%d")
onemonthago = (dt.date.today() - dt.timedelta(30)).strftime("%Y-%m-%d")
cli = ArgumentParser('Volatile Bot-Tournament.', formatter_class=ArgumentDefaultsHelpFormatter)
cli.add_argument('-s', '--symbols', type=str, nargs='+', help=SUPPRESS)
cli.add_argument('--capital', type=float, default=100000.0, help='Bots start with this available capital at '
'the beginning of the tournament. ')
cli.add_argument('--currency', type=str, default='USD', help='Currency of the capital in input.')
cli.add_argument('--start', type=str, default=onemonthago, help='Approximate initial date of the bot-tournament. Format: '
'YY-MM-DD`.')
cli.add_argument('--end', type=str, default=today, help='Approximate final date of the bot-tournament. Format: '
'YY-MM-DD`.')
args = cli.parse_args()
if args.capital < 0:
raise Exception("Capital must be a non-negative number.")
if args.start >= args.end:
raise Exception("Start date must be before end date.")
print('\nDownloading all available closing prices in the last year...')
if args.symbols is None:
with open("symbols_list.txt", "r") as my_file:
args.symbols = my_file.readlines()[0].split(" ")
# download data
start_download = (dt.datetime.strptime(args.start, '%Y-%m-%d') - dt.timedelta(365)).strftime("%Y-%m-%d")
data = download(args.symbols, start=start_download, end=args.end)
tickers = data["tickers"]
price = data['price']
logp = np.log(price)
# number of tournament days
num_days = int(np.sum(data['dates'] >= args.start))
# convert currencies to most frequent one
for i, curr in enumerate(data['currencies']):
if curr != data['default_currency']:
logp[i] = convert_currency(logp[i], np.array(data['exchange_rates'][curr]), type='forward')
price[i] = np.exp(logp[i])
# convert initial capital
if args.currency == data['default_currency']:
xrate = 1.0
elif args.currency in data['exchange_rates']:
xrate = np.array(data['exchange_rates'][args.currency])[-num_days]