Streamlit

What is Streamlit?

Streamlit is an open-source Python library that allows you to create beautiful, interactive web applications for data science and machine learning projects without requiring front-end development skills (like HTML, CSS, or JavaScript).

In essence, it lets data scientists and ML engineers transform their data scripts, models, and analyses into shareable web apps very quickly and with minimal code.

Sample implementation using nexos.ai

  • Install dependencies

  • Define environments NEXOS_API_KEY=team-api-key NEXOS_BASE_URL=https://api.nexos.ai/v1.

import os
import streamlit as st

from openai import OpenAI
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()
# --- Configuration ---
NEXOS_BASE_URL = os.getenv("NEXOS_BASE_URL")
NEXOS_API_KEY = os.getenv("NEXOS_API_KEY")
if not NEXOS_BASE_URL or not NEXOS_API_KEY:
    raise ValueError("Please set NEXOS_BASE_URL and NEXOS_API_KEY in your .env file")

# Configure OpenAI client once, pointing to Nexos
client = OpenAI(
  api_key=NEXOS_API_KEY,
  base_url=NEXOS_BASE_URL # e.g. "https://api.nexos.ai/v1"
)

st.title("Chat via Nexos.ai")

user_input = st.text_input("Ask something:")

if user_input:
    try:
        response = client.chat.completions.create(
            model='Claude Haiku 4.5', # or any other OpenAI-compatible model ID available to you 
            messages=[{"role": "user", "content": user_input}]
        )
        st.write("Nexos Response:")
        st.write(response.choices[0].message.content)
    except Exception as e:
        st.error(f"Error calling Nexos: {e}")

You can use any open AI compatible model. To check what models are available for you, call Gateway API | nexos.ai documentationarrow-up-right You can use either nexos_model_idor id as model.

Last updated