The official Protean Streamlit library
Project description
Protean SDK Streamlit
The CoGrow Protean Streamlit library provides functionality that simplifies integration of Streamlit applications with Protean platform.
Installation
# install from PyPI
pip install cogrow-protean-streamlit
Protean Authenticator
ProteanAuthenticator allows Streamlit applications to leverage Protean platform authentication using OAuth2 Resource Server pattern.
Usage
Using ProteanAuthenticator is as simple as importing the module, initializing an instance with the OAuth2 issuer URI and calling authenticate to verify logged-in user's credentials:
import streamlit as st
from protean_streamlit import ProteanAuthenticator
protean_authenticator = ProteanAuthenticator("https://keycloak.cogrow.tech/realms/cogrow")
protean_authenticator.authenticate()
if protean_authenticator.is_logged_in:
st.title("Protean Streamlit App")
You could use Protean bearer token to authenticate and access all Protean platform APIs:
import streamlit as st
from openai import OpenAI
from protean import Protean
from protean_streamlit import ProteanAuthenticator
protean_authenticator = ProteanAuthenticator("https://keycloak.cogrow.tech/realms/cogrow")
protean_authenticator.authenticate()
if protean_authenticator.is_logged_in:
st.title("💬 Chatbot")
# Use Protean APIs to fetch the user profile details
protean_client = Protean(base_url=st.context.headers.get('Origin'), api_key=protean_authenticator.bearer_token)
user_profile = protean_client.user.get_user_profile()
with st.sidebar:
st.markdown(f"### 👤 Logged in as: [{user_profile.fullname}](mailto:{user_profile.email})")
if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
for msg in st.session_state.messages:
st.chat_message(msg["role"]).write(msg["content"])
if prompt := st.chat_input():
client = OpenAI(api_key=protean_authenticator.bearer_token, base_url=f"{st.context.headers.get('Origin')}/api/inference/text")
st.session_state.messages.append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
response = client.chat.completions.create(model="llama-3.2-1b-instruct", messages=st.session_state.messages)
msg = response.choices[0].message.content
st.session_state.messages.append({"role": "assistant", "content": msg})
st.chat_message("assistant").write(msg)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cogrow_protean_streamlit-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cogrow_protean_streamlit-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22f93261d0dc582b95295f3bbbcde2978450f0df9e19a28b758ae3487e3e1b82
|
|
| MD5 |
0b5715a523aefc08a017589e8c17444b
|
|
| BLAKE2b-256 |
a01df157f8247fcd3432e56f9e005d7b0f0c96bfdb9d574b32952324dc44d170
|