agent-reference-implemenation / app_agent_config.py
Chris4K's picture
Update app_agent_config.py
32df215 verified
raw
history blame
3.48 kB
# app_agent_config.py
import streamlit as st
from tool_loader import ToolLoader
from tool_config import tool_names
from logger import log_enabled
from PIL import Image
import numpy as np
class AgentConfig:
def __init__(self):
self.tool_checkboxes = []
self.url_endpoint = ""
self.image = []
self.document = ""
self.log_enabled = False
self.context = ""
self.tool_loader = ToolLoader(tool_names)
def configure(self):
st.markdown("Change the agent's configuration here.")
self.url_endpoint = st.selectbox("Select Inference URL", [
"https://api-inference.huggingface.co/models/bigcode/starcoder",
"https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
"https://api-inference.huggingface.co/models/gpt2"
])
tool_loader = ToolLoader(tool_names)
self.log_enabled = st.checkbox("Enable Logging")
self.tool_checkboxes = [st.checkbox(f"{tool.name} --- {tool.description} ") for tool in tool_loader.tools]
def content_and_context(self):
self.context = st.text_area("Context")
self.image = st.camera_input("Take a picture")
img_file_buffer = st.file_uploader('Upload a PNG image', type='png')
if img_file_buffer is not None:
image_raw = Image.open(img_file_buffer)
#global image
self.image = np.array(image_raw)
########
st.image(agent_config.image)
uploaded_file = st.file_uploader("Choose a pdf", type='pdf')
if uploaded_file is not None:
# To read file as bytes:
pdf_document = uploaded_file.getvalue()
self.document = pdf_document
st.write(pdf_document)
uploaded_txt_file = st.file_uploader("Choose a txt", type='txt')
if uploaded_txt_file is not None:
# To read file as bytes:
txt_document = uploaded_txt_file.getvalue()
self.document = txt_document
st.write(txt_document)
uploaded_csv_file = st.file_uploader("Choose a csv", type='csv')
if uploaded_csv_file is not None:
# To read file as bytes:
csv_document = uploaded_csv_file.getvalue()
self.document = csv_document
st.write(csv_document)
uploaded_csv_file = st.file_uploader("Choose audio", type='wav')
if uploaded_csv_file is not None:
# To read file as bytes:
csv_document = uploaded_csv_file.getvalue()
self.document = csv_document
st.write(csv_document)
uploaded_csv_file = st.file_uploader("Choose video", type='avi')
if uploaded_csv_file is not None:
# To read file as bytes:
csv_document = uploaded_csv_file.getvalue()
self.document = csv_document
st.write(csv_document)
# To convert to a string based IO:
#stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
#st.write(stringio)
# To read file as string:
#string_data = stringio.read()
#st.write(string_data)
# Can be used wherever a "file-like" object is accepted:
dataframe = pd.read_csv(uploaded_file)
st.write(dataframe)