CoolFace
Apppublic

ProNerd/Director_Demo

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py95 linesDownload Raw Back to root
1import streamlit as st2import requests3import json4import os5import datetime6 7# Streamlit app8st.title("The Session Director")9st.write("Multi AI Models Running As a Team")10 11# OpenRouter API setup12API_KEY = st.secrets.get("OPENROUTER_API_KEY", "your-openrouter-api-key-here")13URL = "https://openrouter.ai/api/v1/chat/completions"14 15# Initialize session state for messages16if "messages" not in st.session_state:17    st.session_state["messages"] = []18if "prompt_input" not in st.session_state:19    st.session_state["prompt_input"] = "Prompts Go Here"20 21# UX elements22model = st.selectbox("Choose Model", [23    "google/gemini-2.0-flash-001",24    "google/gemma-3-27b-it:free",25    "deepseek/deepseek-chat-v3-0324:free"26])27role = st.selectbox("Assign Role", ["scribe", "unpacker", "flyover"])28 29# Two columns for output30col1, col2 = st.columns(2)31 32# Display previous messages33for msg in st.session_state.messages:34    with st.container():35        st.markdown(f"**{msg['role'].title()}:** {msg['content']}")36 37# Prompt input at the bottom38prompt = st.text_input("Enter Prompt", key="prompt_input")39 40# Send button41if st.button("Send Prompt"):42    # Clear the input prompt at the beginning of the button action43    st.session_state.prompt_input = ""44 45    tagged_prompt = f"[{role}] {st.session_state.prompt_input}"46    payload = {47        "model": model,48        "messages": [49            {"role": "system", "content": "You are a band member and the music is innovation."},50            {"role": "user", "content": tagged_prompt}51        ]52    }53    response = requests.post(54        URL,55        headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},56        data=json.dumps(payload)57    )58    if response.status_code == 200:59        result = response.json()60        output = result["choices"][0]["message"]["content"]61 62        # Display new message63        with st.container():64            st.markdown(f"**{role.title()}:** {output}")65        st.session_state.messages.append({"role": role, "content": output})66 67        # Display output in columns68        if role == "unpacker":69            col1.markdown(f"**Unpacker Output:**\n\n{output}")70        elif role == "flyover":71            col2.markdown(f"**Flyover Output:**\n\n{output}")72        elif role == "scribe":73            # Scribe output can be in the main area or a dedicated section74            st.markdown(f"**Scribe Output:**\n\n{output}")75 76        # Save to session log as JSON77        timestamp = datetime.datetime.now().isoformat()78        log_entry = {79            "timestamp": timestamp,80            "role": role,81            "prompt": tagged_prompt,82            "model": model,83            "response": output84        }85        try:86            with open("session_log.json", "a") as f:87                f.write(json.dumps(log_entry) + "\n")88            st.success("Saved to session_log.json!")89        except Exception as e:90            st.error(f"Error writing to session_log.json: {e}")91            st.error(f"Current working directory: {os.getcwd()}")92 93    else:94        st.error(f"Oops: {response.status_code} - {response.text}")95        st.error(f"Current working directory: {os.getcwd()}")