Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,14 @@ import os
|
|
3 |
import gradio as gr
|
4 |
import json
|
5 |
from huggingface_hub import InferenceClient
|
|
|
6 |
|
7 |
path = '/Users/thiloid/Desktop/Avah/chromafiles'
|
8 |
if not os.path.exists(path):
|
9 |
path = "/home/user/app/chromafiles"
|
10 |
|
11 |
print(path)
|
12 |
-
|
13 |
client = chromadb.PersistentClient(path=path)
|
14 |
print(client.heartbeat())
|
15 |
print(client.get_version())
|
@@ -157,13 +158,15 @@ def responsefull(
|
|
157 |
#return "Bitte spezifiziere deine Frage."
|
158 |
if responsecritical(prompt)==False:
|
159 |
return "Es scheint so, als sei dies keine Frage, die sich auf Bundestagswahl oder den Wahl-O-Maten bezieht"
|
160 |
-
|
161 |
if selected_option == "Keine These ausgewählt":
|
|
|
162 |
query_prompt=format_prompt(prompt,history)
|
163 |
selected_optionfull = " Die Frage bezieht sich auf keine These speziell und ist somit allgemeiner zu behandeln."
|
164 |
else:
|
165 |
-
|
166 |
-
|
|
|
167 |
if contains_op(prompt)==True:
|
168 |
return "Als KI Assitenz kann ich dich nur beraten, jedoch bleibe ich neutral und werde keine Position einehmen. Frage mich aber gerne etwas anderes zum Wahl-O-Maten."
|
169 |
#time.sleep(10)
|
@@ -172,21 +175,22 @@ def responsefull(
|
|
172 |
|
173 |
prompt= prompt + selected_optionfull
|
174 |
addon=""
|
175 |
-
|
|
|
176 |
query_texts=[query_prompt],
|
177 |
n_results=8,
|
178 |
#where={"source": "google-docs"}
|
179 |
#where_document={"$contains":"search_string"}
|
180 |
)
|
181 |
#print("REsults")
|
182 |
-
|
183 |
#print("_____")
|
184 |
-
|
185 |
|
186 |
#sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
#print(str(prompt)+"\n\n"+str(combination))
|
191 |
if(len(results)>1):
|
192 |
addon="Bitte berücksichtige bei deiner Antwort folgende Auszüge aus unserer Wahlhilfe Datenbank, sofern sie für die Antwort erforderlich sind. Beantworte die Frage knapp und präzise. Ignoriere unpassende Datenbank-Auszüge OHNE sie zu kommentieren, zu erwähnen oder aufzulisten:\n"+"\n".join(results)
|
|
|
3 |
import gradio as gr
|
4 |
import json
|
5 |
from huggingface_hub import InferenceClient
|
6 |
+
import pandas as pd
|
7 |
|
8 |
path = '/Users/thiloid/Desktop/Avah/chromafiles'
|
9 |
if not os.path.exists(path):
|
10 |
path = "/home/user/app/chromafiles"
|
11 |
|
12 |
print(path)
|
13 |
+
mragdata= pd.read_excel("mragdata.xlsx")
|
14 |
client = chromadb.PersistentClient(path=path)
|
15 |
print(client.heartbeat())
|
16 |
print(client.get_version())
|
|
|
158 |
#return "Bitte spezifiziere deine Frage."
|
159 |
if responsecritical(prompt)==False:
|
160 |
return "Es scheint so, als sei dies keine Frage, die sich auf Bundestagswahl oder den Wahl-O-Maten bezieht"
|
161 |
+
arag=False
|
162 |
if selected_option == "Keine These ausgewählt":
|
163 |
+
arag=True
|
164 |
query_prompt=format_prompt(prompt,history)
|
165 |
selected_optionfull = " Die Frage bezieht sich auf keine These speziell und ist somit allgemeiner zu behandeln."
|
166 |
else:
|
167 |
+
results=mpragdata[mpragdata["These: These"] == selected_option]["testnew"]
|
168 |
+
#query_prompt=selected_option
|
169 |
+
#selected_optionfull = " Die Nutzer Frage bezieht sich auf folgende Wahl-O-Mat These: " + selected_option
|
170 |
if contains_op(prompt)==True:
|
171 |
return "Als KI Assitenz kann ich dich nur beraten, jedoch bleibe ich neutral und werde keine Position einehmen. Frage mich aber gerne etwas anderes zum Wahl-O-Maten."
|
172 |
#time.sleep(10)
|
|
|
175 |
|
176 |
prompt= prompt + selected_optionfull
|
177 |
addon=""
|
178 |
+
if arag:
|
179 |
+
results=collection.query(
|
180 |
query_texts=[query_prompt],
|
181 |
n_results=8,
|
182 |
#where={"source": "google-docs"}
|
183 |
#where_document={"$contains":"search_string"}
|
184 |
)
|
185 |
#print("REsults")
|
186 |
+
print(results)
|
187 |
#print("_____")
|
188 |
+
dists=["<br><small>(relevance: "+str(round((1-d)*100)/100)+";" for d in results['distances'][0]]
|
189 |
|
190 |
#sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
191 |
+
results=results['documents'][0]
|
192 |
+
combination = zip(results,dists)
|
193 |
+
combination = [' '.join(triplets) for triplets in combination]
|
194 |
#print(str(prompt)+"\n\n"+str(combination))
|
195 |
if(len(results)>1):
|
196 |
addon="Bitte berücksichtige bei deiner Antwort folgende Auszüge aus unserer Wahlhilfe Datenbank, sofern sie für die Antwort erforderlich sind. Beantworte die Frage knapp und präzise. Ignoriere unpassende Datenbank-Auszüge OHNE sie zu kommentieren, zu erwähnen oder aufzulisten:\n"+"\n".join(results)
|