Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,34 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import streamlit as st
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
# 🔒 Hitelesítés HF tokennel
|
| 6 |
HF_TOKEN = st.secrets["HF_TOKEN"]
|
| 7 |
client = InferenceClient(token=HF_TOKEN)
|
| 8 |
|
| 9 |
-
st.
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
"Segíts eligazodni a modern hadviselés etikai dilemmáiban, válaszolj tisztelettel, higgadtan és bölcsen."
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
# 👥 Felhasználó input – játékos kérdései
|
| 19 |
-
user_input = st.text_area("Írd be a dilemmádat vagy kérdésedet Major Plato számára:", height=150)
|
| 20 |
-
|
| 21 |
-
# ⚙️ Paraméterek
|
| 22 |
-
max_tokens = st.sidebar.slider("Max token", min_value=50, max_value=500, value=200, step=50)
|
| 23 |
-
temperature = st.sidebar.slider("Temperature", min_value=0.2, max_value=1.0, value=0.7, step=0.1)
|
| 24 |
-
|
| 25 |
-
if st.button("Küldés"):
|
| 26 |
-
if not user_input.strip():
|
| 27 |
-
st.error("Kérlek, írj be egy kérdést vagy dilemmát!")
|
| 28 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
messages = [
|
| 30 |
-
{"role":
|
| 31 |
-
{"role":
|
| 32 |
]
|
| 33 |
with st.spinner("Major Plato gondolkodik..."):
|
| 34 |
resp = client.chat_completion(
|
| 35 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
| 36 |
messages=messages,
|
| 37 |
-
max_tokens=
|
| 38 |
-
temperature=
|
| 39 |
)
|
| 40 |
-
|
| 41 |
-
st.
|
| 42 |
-
st.write(answer)
|
|
|
|
| 1 |
+
import os, streamlit as st
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
| 4 |
HF_TOKEN = st.secrets["HF_TOKEN"]
|
| 5 |
client = InferenceClient(token=HF_TOKEN)
|
| 6 |
|
| 7 |
+
st.title("🎖️ Major Plato – Szimulátor")
|
| 8 |
+
system = open("system.txt").read() if os.path.exists("system.txt") else ""
|
| 9 |
+
scenario = open("scenario.txt").read() if os.path.exists("scenario.txt") else ""
|
| 10 |
+
file_up = st.file_uploader("Töltsd fel a forgatókönyv fájlt (.txt):", type="txt")
|
| 11 |
+
user_in = st.text_area("Vagy írd be a kérdésedet:")
|
| 12 |
|
| 13 |
+
if st.button("Indítás"):
|
| 14 |
+
if (not file_up and not user_in.strip()) or not system.strip():
|
| 15 |
+
st.error("Hiányzik a system.txt vagy user input/fájl!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
else:
|
| 17 |
+
usr_content = ""
|
| 18 |
+
if file_up:
|
| 19 |
+
usr_content += file_up.read().decode("utf-8")
|
| 20 |
+
if user_in.strip():
|
| 21 |
+
usr_content += "\n\n" + user_in.strip()
|
| 22 |
messages = [
|
| 23 |
+
{"role":"system","content":system},
|
| 24 |
+
{"role":"user","content":usr_content}
|
| 25 |
]
|
| 26 |
with st.spinner("Major Plato gondolkodik..."):
|
| 27 |
resp = client.chat_completion(
|
| 28 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
| 29 |
messages=messages,
|
| 30 |
+
max_tokens=200,
|
| 31 |
+
temperature=0.7
|
| 32 |
)
|
| 33 |
+
st.subheader("🗣️ Válasz:")
|
| 34 |
+
st.write(resp.choices[0].message.content)
|
|
|