Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
import pdfplumber
|
3 |
import docx
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
-
import
|
6 |
|
7 |
st.title("JAI")
|
8 |
|
@@ -58,33 +58,7 @@ def generate_response(input_text):
|
|
58 |
response = tokenizer.decode(outputs.logits.argmax(dim=1)[0])
|
59 |
return response
|
60 |
|
61 |
-
#
|
62 |
-
if st.session_state.previous_conversations:
|
63 |
-
# Először hozz létre egy üres FAISS indexet
|
64 |
-
index = faiss.IndexFlatL2(embedding_dimension) # Az embedding_dimension a vektormérete az előző beszélgetések reprezentálásához
|
65 |
-
|
66 |
-
# Az előző beszélgetéseket reprezentáló vektorokat hozzáadhatod az indexhez
|
67 |
-
previous_conversation_vectors = generate_vectors_from_previous_conversations(st.session_state.previous_conversations)
|
68 |
-
for conversation_vector in previous_conversation_vectors:
|
69 |
-
index.add(conversation_vector)
|
70 |
-
|
71 |
-
# Keresés egy adott lekérdezés vektor alapján
|
72 |
-
query_vector = generate_vector_from_text(input_text) # A lekérdezés szövegből létrehozott vektor
|
73 |
-
k = 5 # A legjobb 5 hasonlóságú beszélgetés visszaadása
|
74 |
-
D, I = index.search(query_vector, k) # D: távolságok, I: indexek
|
75 |
-
|
76 |
-
# Azon beszélgetések visszaadása, amelyek a legjobban illeszkednek a lekérdezéshez
|
77 |
-
relevant_conversations = [st.session_state.previous_conversations[i] for i in I]
|
78 |
-
|
79 |
-
# Az eredmények megjelenítése
|
80 |
-
st.subheader("Legjobban Illeszkedő Beszélgetések:")
|
81 |
-
for i, conversation in enumerate(relevant_conversations):
|
82 |
-
st.write(f"{i+1}. Kérdés: {conversation['input_text']}")
|
83 |
-
st.write(f" Válasz: {conversation['response']}")
|
84 |
-
else:
|
85 |
-
st.info("Nincsenek előző beszélgetések az indexeléshez.")
|
86 |
-
|
87 |
-
# Dokumentum feltöltése drag and drop segítségével
|
88 |
document_file = st.file_uploader("Húzd ide a dokumentumot vagy kattints a feltöltéshez", type=["pdf", "docx", "doc"])
|
89 |
|
90 |
if document_file is not None:
|
|
|
2 |
import pdfplumber
|
3 |
import docx
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
+
import torch
|
6 |
|
7 |
st.title("JAI")
|
8 |
|
|
|
58 |
response = tokenizer.decode(outputs.logits.argmax(dim=1)[0])
|
59 |
return response
|
60 |
|
61 |
+
# Dokumentumfeltöltés feldolgozása
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
document_file = st.file_uploader("Húzd ide a dokumentumot vagy kattints a feltöltéshez", type=["pdf", "docx", "doc"])
|
63 |
|
64 |
if document_file is not None:
|