Spaces:
Sleeping
Sleeping
Agri Karem
commited on
Commit
·
48b2505
1
Parent(s):
92f8d17
Infört inbyggt lösenordsskydd med lösenord agrikaremexergi
Browse files
app.py
CHANGED
@@ -8,9 +8,9 @@ import spacy
|
|
8 |
from sentence_transformers import CrossEncoder
|
9 |
from dotenv import load_dotenv
|
10 |
|
11 |
-
# Ladda spaCy-modellen (använd
|
12 |
try:
|
13 |
-
nlp = spacy.load("en_core_web_sm")
|
14 |
except OSError:
|
15 |
from spacy.cli import download
|
16 |
download("en_core_web_sm")
|
@@ -215,18 +215,48 @@ def chat_rag(question, history, user_profile, cache):
|
|
215 |
cache[normalized_q] = answer
|
216 |
return "", history, user_profile, cache
|
217 |
|
218 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
with gr.Blocks() as demo:
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
if __name__ == "__main__":
|
232 |
demo.launch()
|
|
|
8 |
from sentence_transformers import CrossEncoder
|
9 |
from dotenv import load_dotenv
|
10 |
|
11 |
+
# Ladda spaCy-modellen (använd "en_core_web_sm" eller byt ut mot "sv_core_news_sm" om du vill)
|
12 |
try:
|
13 |
+
nlp = spacy.load("en_core_web_sm")
|
14 |
except OSError:
|
15 |
from spacy.cli import download
|
16 |
download("en_core_web_sm")
|
|
|
215 |
cache[normalized_q] = answer
|
216 |
return "", history, user_profile, cache
|
217 |
|
218 |
+
# --- Inbyggt lösenordsskydd ---
|
219 |
+
|
220 |
+
# Definiera ditt lösenord
|
221 |
+
PASSWORD = "agrikaremexergi"
|
222 |
+
|
223 |
+
def login(input_password):
|
224 |
+
if input_password == PASSWORD:
|
225 |
+
return gr.update(visible=True), "Inloggning lyckades!"
|
226 |
+
else:
|
227 |
+
return gr.update(visible=False), "Fel lösenord, försök igen."
|
228 |
+
|
229 |
+
# --- Gradio UI ---
|
230 |
with gr.Blocks() as demo:
|
231 |
+
# Inloggningspanel (visas först)
|
232 |
+
with gr.Column(visible=True) as login_panel:
|
233 |
+
gr.Markdown("## Logga in")
|
234 |
+
password_input = gr.Textbox(label="Ange lösenord", type="password")
|
235 |
+
login_button = gr.Button("Logga in")
|
236 |
+
login_message = gr.Markdown("")
|
237 |
+
|
238 |
+
# Huvudapp-panel (gömd tills rätt lösenord anges)
|
239 |
+
with gr.Column(visible=False) as main_app_panel:
|
240 |
+
gr.Markdown("## 💬 OpenAI RAG-Chat med FAISS + Re-Ranking")
|
241 |
+
chatbot = gr.Chatbot(label="RAG-Chat", type="messages")
|
242 |
+
msg = gr.Textbox(label="Ställ en fråga...")
|
243 |
+
send = gr.Button("Skicka")
|
244 |
+
state = gr.State([]) # Chatthistorik
|
245 |
+
profile = gr.State({}) # Användarprofil
|
246 |
+
cache_state = gr.State({}) # Cache för återkommande frågor
|
247 |
+
|
248 |
+
send.click(
|
249 |
+
fn=chat_rag,
|
250 |
+
inputs=[msg, state, profile, cache_state],
|
251 |
+
outputs=[msg, chatbot, profile, cache_state]
|
252 |
+
)
|
253 |
+
|
254 |
+
# Koppla login-knappen till inloggningsfunktionen
|
255 |
+
login_button.click(
|
256 |
+
fn=login,
|
257 |
+
inputs=[password_input],
|
258 |
+
outputs=[main_app_panel, login_message]
|
259 |
+
)
|
260 |
|
261 |
if __name__ == "__main__":
|
262 |
demo.launch()
|