Spaces:
Sleeping
Sleeping
tomas.helmfridsson
commited on
Commit
·
d5bc552
1
Parent(s):
b93e9df
update guis 4
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ def load_vectorstore():
|
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
with gr.Row():
|
27 |
-
status_text = gr.Markdown("🔄 Laddar modellen, vänta...")
|
28 |
|
29 |
vectorstore, loaded_files = load_vectorstore()
|
30 |
llm_pipeline = pipeline("text-generation", model="tiiuae/falcon-rw-1b", device=-1)
|
@@ -32,22 +32,22 @@ with gr.Blocks() as demo:
|
|
32 |
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vectorstore.as_retriever())
|
33 |
|
34 |
loaded_list = "\n".join([f"- {f}" for f in loaded_files])
|
35 |
-
status_text.visible = False
|
36 |
-
gr.Markdown(f"✅ Klar! Du kan nu ställa frågor om dokumenten nedan:\n\n{loaded_list}")
|
37 |
|
38 |
def chat_fn(message, history):
|
39 |
if len(message) > 1000:
|
40 |
-
return
|
41 |
try:
|
42 |
svar = qa_chain.invoke({"query": message})
|
43 |
except Exception as e:
|
44 |
-
return
|
45 |
-
return
|
|
|
|
|
46 |
|
47 |
gr.ChatInterface(
|
48 |
fn=chat_fn,
|
49 |
title="🌟 Dokumentassistent (Svenska)",
|
50 |
-
chatbot=gr.Chatbot(type="messages"),
|
51 |
description="Hej! Jag är din dokumentassistent. Ställ en fråga baserat på innehållet i dina PDF-filer."
|
52 |
)
|
53 |
|
|
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
with gr.Row():
|
27 |
+
status_text = gr.Markdown("🔄 Laddar modellen, vänta...", elem_id="status-text")
|
28 |
|
29 |
vectorstore, loaded_files = load_vectorstore()
|
30 |
llm_pipeline = pipeline("text-generation", model="tiiuae/falcon-rw-1b", device=-1)
|
|
|
32 |
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vectorstore.as_retriever())
|
33 |
|
34 |
loaded_list = "\n".join([f"- {f}" for f in loaded_files])
|
|
|
|
|
35 |
|
36 |
def chat_fn(message, history):
|
37 |
if len(message) > 1000:
|
38 |
+
return {"role": "assistant", "content": "⚠️ Din fråga är för lång (" + str(len(message)) + " tecken). Försök ställa en mer specifik fråga."}
|
39 |
try:
|
40 |
svar = qa_chain.invoke({"query": message})
|
41 |
except Exception as e:
|
42 |
+
return {"role": "assistant", "content": f"Ett fel uppstod vid bearbetning av frågan: {str(e)}"}
|
43 |
+
return {"role": "assistant", "content": svar["result"]}
|
44 |
+
|
45 |
+
gr.Markdown(f"✅ Klar! Du kan nu ställa frågor om dokumenten nedan:\n\n{loaded_list}", elem_id="status-text")
|
46 |
|
47 |
gr.ChatInterface(
|
48 |
fn=chat_fn,
|
49 |
title="🌟 Dokumentassistent (Svenska)",
|
50 |
+
chatbot=gr.Chatbot(type="messages", reverse=True),
|
51 |
description="Hej! Jag är din dokumentassistent. Ställ en fråga baserat på innehållet i dina PDF-filer."
|
52 |
)
|
53 |
|