ErikH commited on
Commit
6126668
1 Parent(s): 66f368c

Update pages/bot.py

Browse files
Files changed (1) hide show
  1. pages/bot.py +25 -6
pages/bot.py CHANGED
@@ -12,6 +12,7 @@ from transformers import AutoModel
12
  from langchain.prompts import ChatPromptTemplate
13
  from langchain.schema import StrOutputParser
14
  from langchain.schema.runnable import RunnablePassthrough
 
15
 
16
  ###########
17
  #pip install faiss-cpu
@@ -76,7 +77,19 @@ def get_vectorstore():
76
  vectorstoreDB = FAISS.load_local(save_directory, embeddings)
77
  return vectorstoreDB
78
 
 
79
 
 
 
 
 
 
 
 
 
 
 
 
80
  def main():
81
  #if os.path.exists("./Store"): #Nutzereingabe nur eingelesen, wenn vectorstore angelegt
82
  user_question = st.text_area("Stell mir eine Frage: ")
@@ -92,13 +105,13 @@ def main():
92
  st.text(user_question)
93
 
94
  ##IDEE Text Generation
95
- generator = pipeline('text-generation', model = 'gpt2')
96
- answer = generator(context, max_length = 30, num_return_sequences=3)
97
 
98
- st.text("FORMATIERTE ANTWORT:")
99
  #st.text_area()
100
- st.text(answer)
101
- st.text(type(answer))
102
 
103
  # Erstelle die Question Answering-Pipeline für Deutsch
104
  qa_pipeline = pipeline("question-answering", model="deutsche-telekom/bert-multi-english-german-squad2", tokenizer="deutsche-telekom/bert-multi-english-german-squad2")
@@ -110,12 +123,18 @@ def main():
110
  st.text("Basisantwort:")
111
  st.text(answer["answer"])
112
  st.text(answer)
 
 
 
 
 
113
 
114
-
115
  generator = pipeline('text-generation', model = 'tiiuae/falcon-40b')
116
  generator(answer, max_length = 30, num_return_sequences=3)
117
  st.text("Generierte Erweiterung:")
118
  st.text(generator)
 
119
 
120
  """
121
  #IDEE Retriever erweitern
 
12
  from langchain.prompts import ChatPromptTemplate
13
  from langchain.schema import StrOutputParser
14
  from langchain.schema.runnable import RunnablePassthrough
15
+ from langchain.chains import ConversationalRetrievalChain
16
 
17
  ###########
18
  #pip install faiss-cpu
 
77
  vectorstoreDB = FAISS.load_local(save_directory, embeddings)
78
  return vectorstoreDB
79
 
80
+ ######
81
 
82
+ def get_conversation_chain(vectorstore):
83
+ llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})
84
+ conversation_chain = ConversationalRetrievalChain.from_llm(
85
+ llm=llm,
86
+ retriever=vectorstore.as_retriever()
87
+ )
88
+ return conversation_chain
89
+
90
+
91
+
92
+ #####
93
  def main():
94
  #if os.path.exists("./Store"): #Nutzereingabe nur eingelesen, wenn vectorstore angelegt
95
  user_question = st.text_area("Stell mir eine Frage: ")
 
105
  st.text(user_question)
106
 
107
  ##IDEE Text Generation
108
+ #generator = pipeline('text-generation', model = 'gpt2')
109
+ #answer = generator(context, max_length = 30, num_return_sequences=3)
110
 
111
+ #st.text("FORMATIERTE ANTWORT:")
112
  #st.text_area()
113
+ #st.text(answer)
114
+ #st.text(type(answer))
115
 
116
  # Erstelle die Question Answering-Pipeline für Deutsch
117
  qa_pipeline = pipeline("question-answering", model="deutsche-telekom/bert-multi-english-german-squad2", tokenizer="deutsche-telekom/bert-multi-english-german-squad2")
 
123
  st.text("Basisantwort:")
124
  st.text(answer["answer"])
125
  st.text(answer)
126
+
127
+ ######
128
+
129
+ newA = get_conversation_chain(get_vectorstore())
130
+ st.text(newA)
131
 
132
+ """
133
  generator = pipeline('text-generation', model = 'tiiuae/falcon-40b')
134
  generator(answer, max_length = 30, num_return_sequences=3)
135
  st.text("Generierte Erweiterung:")
136
  st.text(generator)
137
+ """
138
 
139
  """
140
  #IDEE Retriever erweitern