Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
#
|
6 |
st.sidebar.header("API beállítások")
|
7 |
provider_choice = st.sidebar.selectbox(
|
8 |
"Inference provider",
|
@@ -24,7 +28,68 @@ else:
|
|
24 |
st.stop()
|
25 |
client = InferenceClient(token=HF_TOKEN, provider="custom", api_key=custom_key)
|
26 |
|
27 |
-
#
|
28 |
-
st.set_page_config(page_title="Major Plato Szimulátor", layout="wide")
|
29 |
st.title("🎖️ Major Plato – Katonai Etikai Szimuláció")
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
|
3 |
+
# ⚙️ Oldal beállítása – csak egyszer és elsőként hívható
|
4 |
+
st.set_page_config(page_title="Major Plato Szimulátor", layout="wide")
|
5 |
+
|
6 |
+
import os
|
7 |
from huggingface_hub import InferenceClient
|
8 |
|
9 |
+
# 🧭 API provider választás
|
10 |
st.sidebar.header("API beállítások")
|
11 |
provider_choice = st.sidebar.selectbox(
|
12 |
"Inference provider",
|
|
|
28 |
st.stop()
|
29 |
client = InferenceClient(token=HF_TOKEN, provider="custom", api_key=custom_key)
|
30 |
|
31 |
+
# Oldal címe
|
|
|
32 |
st.title("🎖️ Major Plato – Katonai Etikai Szimuláció")
|
33 |
+
|
34 |
+
# Rendszer prompt betöltése
|
35 |
+
if os.path.exists("system.txt"):
|
36 |
+
system = open("system.txt", encoding="utf-8").read().strip()
|
37 |
+
else:
|
38 |
+
st.error("Hiba: Nincs 'system.txt' fájl! Ide írd Major Plato karakter leírását.")
|
39 |
+
st.stop()
|
40 |
+
|
41 |
+
# Forgatókönyv feltöltése vagy kézi kérdés
|
42 |
+
scenario = ""
|
43 |
+
uploaded = st.file_uploader("Töltsd fel forgatókönyv fájlt (.txt):", type="txt")
|
44 |
+
if uploaded:
|
45 |
+
scenario = uploaded.read().decode("utf-8")
|
46 |
+
|
47 |
+
user_in = st.text_area("Vagy írd be kézzel a kérdésedet:")
|
48 |
+
|
49 |
+
# Paraméterek az oldalsávban
|
50 |
+
max_tokens = st.sidebar.slider("Max token", 100, 1000, 600, 50)
|
51 |
+
temperature = st.sidebar.slider("Temperature", 0.2, 1.0, 0.7, 0.1)
|
52 |
+
|
53 |
+
# CSS a scrollozható expanderhez
|
54 |
+
st.markdown(
|
55 |
+
"""
|
56 |
+
<style>
|
57 |
+
[data-testid="stExpander"] div[role="button"] + div {
|
58 |
+
max-height: 400px;
|
59 |
+
overflow-y: auto;
|
60 |
+
}
|
61 |
+
</style>
|
62 |
+
""",
|
63 |
+
unsafe_allow_html=True
|
64 |
+
)
|
65 |
+
|
66 |
+
if st.button("Indítás"):
|
67 |
+
if not (scenario.strip() or user_in.strip()):
|
68 |
+
st.error("Kérlek, tölts fel forgatókönyvet vagy írj kérdést!")
|
69 |
+
else:
|
70 |
+
usr_content = scenario.strip()
|
71 |
+
if user_in.strip():
|
72 |
+
usr_content += "\n\n" + user_in.strip()
|
73 |
+
|
74 |
+
messages = [
|
75 |
+
{"role": "system", "content": system},
|
76 |
+
{"role": "user", "content": usr_content}
|
77 |
+
]
|
78 |
+
|
79 |
+
with st.spinner("Major Plato gondolkodik..."):
|
80 |
+
stream = client.chat_completion(
|
81 |
+
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
82 |
+
messages=messages,
|
83 |
+
max_tokens=max_tokens,
|
84 |
+
temperature=temperature,
|
85 |
+
stream=True # folyamatos válasz fogadó
|
86 |
+
)
|
87 |
+
|
88 |
+
placeholder = st.empty()
|
89 |
+
full_resp = ""
|
90 |
+
with st.expander("🗣️ Major Plato válasza:", expanded=True):
|
91 |
+
for chunk in stream:
|
92 |
+
delta = chunk.choices[0].delta.content
|
93 |
+
if delta:
|
94 |
+
full_resp += delta
|
95 |
+
placeholder.markdown(full_resp)
|