Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,67 +1,40 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
-
from fastapi import FastAPI, Request
|
| 5 |
-
from fastapi.responses import StreamingResponse
|
| 6 |
-
import uvicorn
|
| 7 |
-
from threading import Thread
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
uvicorn.run(api_app, host="0.0.0.0", port=7860)
|
| 35 |
-
|
| 36 |
-
# --- STREAMLIT UI LOGIC ---
|
| 37 |
-
# This part handles the visual interface on a hidden port
|
| 38 |
-
def run_ui():
|
| 39 |
-
st.set_page_config(page_title="Core Interface", page_icon="⚡")
|
| 40 |
-
|
| 41 |
-
# Simple CSS for your premium look
|
| 42 |
-
st.markdown("<style>.main { background-color: #121212; color: #e0e0e0; }</style>", unsafe_allow_html=True)
|
| 43 |
-
|
| 44 |
-
SECRET_PIN = os.getenv("PIN", "1234")
|
| 45 |
-
|
| 46 |
-
if "authenticated" not in st.session_state:
|
| 47 |
-
st.session_state["authenticated"] = False
|
| 48 |
-
|
| 49 |
-
if not st.session_state["authenticated"]:
|
| 50 |
-
st.title("System Locked")
|
| 51 |
-
user_input = st.text_input("Enter Access Key", type="password")
|
| 52 |
-
if st.button("Authenticate"):
|
| 53 |
-
if user_input == SECRET_PIN:
|
| 54 |
-
st.session_state["authenticated"] = True
|
| 55 |
-
st.rerun()
|
| 56 |
-
else:
|
| 57 |
-
st.error("Access Denied.")
|
| 58 |
-
else:
|
| 59 |
-
st.title("⚡ Node Status: Online")
|
| 60 |
-
st.success("API is public at /api/generate")
|
| 61 |
-
st.info("Ollama is running on backend port 11434")
|
| 62 |
-
|
| 63 |
-
# This is a bit of a trick: when HF loads port 7860,
|
| 64 |
-
# it will see the FastAPI app. We will use a sub-route for the UI.
|
| 65 |
-
if __name__ == "__main__":
|
| 66 |
-
# If you are running this via streamlit, it executes the UI
|
| 67 |
-
run_ui()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
st.set_page_config(page_title="Core Interface", page_icon="⚡")
|
| 6 |
+
|
| 7 |
+
# Premium look
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
.main { background-color: #0e1117; color: #ffffff; }
|
| 11 |
+
.stTextInput > div > div > input { background-color: #262730; color: white; }
|
| 12 |
+
</style>
|
| 13 |
+
""", unsafe_allow_html=True)
|
| 14 |
+
|
| 15 |
+
PIN = os.getenv("PIN", "1234")
|
| 16 |
+
|
| 17 |
+
if "auth" not in st.session_state:
|
| 18 |
+
st.session_state.auth = False
|
| 19 |
+
|
| 20 |
+
if not st.session_state.auth:
|
| 21 |
+
st.title("🔒 System Restricted")
|
| 22 |
+
val = st.text_input("Access Key", type="password")
|
| 23 |
+
if st.button("Unlock"):
|
| 24 |
+
if val == PIN:
|
| 25 |
+
st.session_state.auth = True
|
| 26 |
+
st.rerun()
|
| 27 |
+
else:
|
| 28 |
+
st.error("Incorrect.")
|
| 29 |
+
else:
|
| 30 |
+
st.title("⚡ Server Node Active")
|
| 31 |
+
st.success("API Path: `/api/generate` (Unlocked)")
|
| 32 |
+
st.info("Model: `qwen2.5:0.5b` pre-loaded.")
|
| 33 |
|
| 34 |
+
# Status Check
|
| 35 |
+
if st.button("Check Ollama Health"):
|
| 36 |
+
try:
|
| 37 |
+
r = requests.get("http://localhost:11434/api/tags")
|
| 38 |
+
st.json(r.json())
|
| 39 |
+
except:
|
| 40 |
+
st.error("Backend offline.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|