Update pages/bot.py
Browse files- pages/bot.py +23 -2
pages/bot.py
CHANGED
@@ -103,6 +103,26 @@ def main():
|
|
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")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
# Frage beantworten
|
107 |
#answer = qa_pipeline(question=question, context=context, top_k=3)
|
108 |
answer = qa_pipeline(question=question, context=context)
|
@@ -111,12 +131,13 @@ def main():
|
|
111 |
st.text("Basisantwort:")
|
112 |
st.text(answer["answer"])
|
113 |
#st.text(answer)
|
114 |
-
|
115 |
#Die Basisantwort müsste man jetzt ausformulieren
|
116 |
text2text_generator = pipeline("text2text-generation", model="google/flan-t5-xxl")
|
117 |
#newText=text2text_generator(question=question, context=answer)
|
118 |
newText=text2text_generator("Formuliere einen neuen Satz. Frage: "+question+ " Antwort: " + answer["answer"])
|
119 |
st.text(newText)
|
120 |
-
|
|
|
121 |
if __name__ == '__main__':
|
122 |
main()
|
|
|
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")
|
105 |
|
106 |
+
|
107 |
+
# Frage beantworten und mehrere Antworten erhalten
|
108 |
+
answers = qa_pipeline(
|
109 |
+
question=question,
|
110 |
+
context=context,
|
111 |
+
#top_k=3, # Anzahl der zurückgegebenen Antworten
|
112 |
+
#top_p=0.8 # Wahrscheinlichkeit der Antwort
|
113 |
+
)
|
114 |
+
|
115 |
+
# Nur Antworten mit mindestens 200 Zeichen behalten
|
116 |
+
filtered_answers = [answer for answer in answers if len(answer['answer']) >= 200]
|
117 |
+
|
118 |
+
# Ergebnisse ausgeben
|
119 |
+
for i, answer in enumerate(filtered_answers):
|
120 |
+
st.text(f"Antwort {i+1}:")
|
121 |
+
st.text(f"Antwort: {answer['answer']}")
|
122 |
+
st.text(f"Konfidenz: {answer['score']}")
|
123 |
+
|
124 |
+
|
125 |
+
"""
|
126 |
# Frage beantworten
|
127 |
#answer = qa_pipeline(question=question, context=context, top_k=3)
|
128 |
answer = qa_pipeline(question=question, context=context)
|
|
|
131 |
st.text("Basisantwort:")
|
132 |
st.text(answer["answer"])
|
133 |
#st.text(answer)
|
134 |
+
|
135 |
#Die Basisantwort müsste man jetzt ausformulieren
|
136 |
text2text_generator = pipeline("text2text-generation", model="google/flan-t5-xxl")
|
137 |
#newText=text2text_generator(question=question, context=answer)
|
138 |
newText=text2text_generator("Formuliere einen neuen Satz. Frage: "+question+ " Antwort: " + answer["answer"])
|
139 |
st.text(newText)
|
140 |
+
"""
|
141 |
+
|
142 |
if __name__ == '__main__':
|
143 |
main()
|