File size: 3,472 Bytes
bc7edcf
f66eefa
a4b5810
 
f66eefa
 
cbf71a4
 
a4b5810
33df268
a4b5810
 
 
 
88c6eeb
 
33df268
a4b5810
 
0a8a7dc
a4b5810
 
 
 
a4630a8
295bbaa
 
 
 
 
8fe1293
 
 
a97c096
 
 
a4b5810
 
 
 
33df268
a4b5810
33df268
a4b5810
33df268
 
a4b5810
 
33df268
a4b5810
33df268
f66eefa
 
 
a4b5810
f66eefa
 
a4b5810
f66eefa
a4b5810
f66eefa
 
a4b5810
f66eefa
a4b5810
 
f66eefa
 
a4b5810
f66eefa
 
 
 
a4b5810
f66eefa
 
 
a4b5810
f66eefa
 
a4b5810
 
f66eefa
a4b5810
f66eefa
 
 
 
 
 
 
 
 
 
 
 
a4b5810
f66eefa
 
 
a4b5810
f66eefa
 
 
 
a4b5810
f66eefa
 
 
 
 
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import streamlit as st

# ⚙️ Oldal beállítása – egyszer, script elején
st.set_page_config(page_title="Major Plato Szimulátor", layout="wide")

import os
from huggingface_hub import InferenceClient

# 🧭 API provider választás a bal oldalon
st.sidebar.header("API beállítások")
provider = st.sidebar.selectbox(
    "Provider",
    options=["auto (HF vagy más)", "custom"],
    help="‘auto’: legjobb elérhető provider; 'custom': írd be saját API-kulcsod"
)

custom_key = ""
if provider == "custom":
    custom_key = st.sidebar.text_input("Saját API-kulcs", type="password")

# Modellválasztás
models = [
    "meta-llama/Llama-3.1-8B-Instruct",
    "deepseek-ai/DeepSeek-R1",
    "google/gemma-3-27b-it",
    "NousResearch/Llama-2-70b-hf",
    "meta-llama/Llama-2-70b-chat-hf",
    "google/gemma-2-27b-it",
    "google/gemma-2-9b-it",
    "google/gemma-2-2b-it",
    "xai-org/grok-1",
    "amazon/MistralLite",
    "mistralai/Mixtral-8x7B-Instruct-v0.1",
    "gpt2",
    "google/gemma-2-2b-it",
    "meta-llama/Llama-2-70b-hf"
]
model_choice = st.sidebar.selectbox("Válaszd ki a modellt:", models)

# InferenceClient konfigurálása
HF_TOKEN = st.secrets["HF_TOKEN"]
if provider == "custom":
    if not custom_key:
        st.sidebar.error("Hiányzik az API-kulcs!")
        st.stop()
    client = InferenceClient(token=HF_TOKEN, provider="custom", api_key=custom_key)
else:
    client = InferenceClient(token=HF_TOKEN, provider="auto")

# Cím és rendszer prompt betöltése
st.title("🎖️ Major Plato – Katonai Etikai Szimuláció")
if os.path.exists("system.txt"):
    system = open("system.txt", encoding="utf-8").read().strip()
else:
    st.error("Hiba: nincs system.txt! Add meg Major Plato karakterét.")
    st.stop()

# Forgatókönyv feltöltés vagy kézi kérdés
scenario = ""
uploaded = st.file_uploader("Forgatókönyv fájl feltöltése (.txt)", type="txt")
if uploaded:
    scenario = uploaded.read().decode("utf-8")
user_in = st.text_area("Kézi kérdés Major Plato számára:")

# Paraméterek a bal sávban
max_tokens = st.sidebar.slider("Max token", 200, 1500, 800, 50)
temperature = st.sidebar.slider("Temperature", 0.2, 1.0, 0.7, 0.1)

# CSS a scrollbar expanderhez
st.markdown(
    """
    <style>
    [data-testid="stExpander"] div[role="button"] + div {
        max-height: 500px;
        overflow-y: auto;
    }
    </style>
    """, unsafe_allow_html=True
)

# Kérdés gomb
if st.button("Indítás"):
    if not (scenario.strip() or user_in.strip()):
        st.error("Adj forgatókönyvet vagy írj kérdést!")
    else:
        usr_content = scenario.strip()
        if user_in.strip():
            usr_content += "\n\n" + user_in.strip()

        messages = [
            {"role": "system", "content": system},
            {"role": "user", "content": usr_content}
        ]

        with st.spinner("Major Plato gondolkodik..."):
            stream = client.chat_completion(
                model=model_choice,
                messages=messages,
                max_tokens=max_tokens,
                temperature=temperature,
                stream=True
            )

        placeholder = st.empty()
        full_resp = ""
        with st.expander("🗣️ Major Plato válasza:", expanded=True):
            for chunk in stream:
                delta = chunk.choices[0].delta.content
                if delta:
                    full_resp += delta
                    placeholder.markdown(full_resp)