Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,9 @@ import gradio as gr
|
|
| 4 |
import json
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
-
path='/Users/thiloid/Desktop/Avah/chromafiles'
|
| 8 |
-
if
|
|
|
|
| 9 |
|
| 10 |
print(path)
|
| 11 |
|
|
@@ -13,9 +14,10 @@ client = chromadb.PersistentClient(path=path)
|
|
| 13 |
print(client.heartbeat())
|
| 14 |
print(client.get_version())
|
| 15 |
print(client.list_collections())
|
|
|
|
| 16 |
from chromadb.utils import embedding_functions
|
| 17 |
default_ef = embedding_functions.DefaultEmbeddingFunction()
|
| 18 |
-
sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="T-Systems-onsite/cross-en-de-roberta-sentence-transformer")
|
| 19 |
|
| 20 |
collection = client.get_collection(name="chromatsc", embedding_function=sentence_transformer_ef)
|
| 21 |
|
|
@@ -23,12 +25,9 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
| 23 |
|
| 24 |
|
| 25 |
def format_prompt(message, history):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# prompt += f" {bot_response}</s> "
|
| 30 |
-
prompt += f"[INST] {message} [/INST]"
|
| 31 |
-
return prompt
|
| 32 |
|
| 33 |
def response(prompt, history, selected_option, temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0):
|
| 34 |
temperature = float(temperature)
|
|
@@ -52,12 +51,12 @@ def response(prompt, history, selected_option, temperature=0.9, max_new_tokens=5
|
|
| 52 |
combination = zip(results, dists)
|
| 53 |
combination = [' '.join(triplets) for triplets in combination]
|
| 54 |
if len(results) > 1:
|
| 55 |
-
addon = "
|
| 56 |
system = "Du heißt Avah und bist ein deutschsprachiges KI-basiertes Wahlhilfe Beratungssystem zum Wahl-O-Maten für die Bundestagswahl 2021. Du nimmst selber keine eigene politische Postion ein!" + addon + "\n\nUser-Anliegen:"
|
| 57 |
-
if selected_option=="Keine These ausgewählt":
|
| 58 |
-
selected_option
|
| 59 |
else:
|
| 60 |
-
selected_option= "Die Nutzer Frage bezieht sich auf folgende Wahl-O-Mat These: "+ selected_option
|
| 61 |
formatted_prompt = format_prompt(system + "\n" + selected_option + "\n" + prompt, history)
|
| 62 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 63 |
output = ""
|
|
@@ -105,7 +104,6 @@ dropdown_options = ["Keine These ausgewählt",
|
|
| 105 |
'Der gesetzliche Mindestlohn soll spätestens im Jahr 2022 auf mindestens 12 Euro erhöht werden.',
|
| 106 |
'Der Flugverkehr soll höher besteuert werden.',
|
| 107 |
'Unternehmen sollen selbst entscheiden, ob sie ihren Beschäftigten das Arbeiten im Homeoffice erlauben.']
|
| 108 |
-
|
| 109 |
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
chatbot = gr.Chatbot(value=[[None, "Hallo mein Name ist Avah (Artificial Voting Advice Helper), deine interaktive Hilfe zum Wahl-O-Maten für die Bundestagswahl 2021. Wenn du Fragen zu Thesen der Wahlhilfe hast, wähle gerne die besagt These aus. Ansonsten kannst du mir auch unabhängig von bestimmten Thesen Fragen stellen."]], render_markdown=True)
|
|
@@ -113,7 +111,8 @@ with gr.Blocks() as demo:
|
|
| 113 |
textbox = gr.Textbox(label="Your Question")
|
| 114 |
|
| 115 |
def combined_response(prompt, history, dropdown_value):
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
submit_button = gr.Button("Submit")
|
| 119 |
|
|
@@ -123,9 +122,8 @@ with gr.Blocks() as demo:
|
|
| 123 |
outputs=chatbot,
|
| 124 |
)
|
| 125 |
|
| 126 |
-
demo.launch(
|
| 127 |
|
| 128 |
-
|
| 129 |
print("Interface up and running!")
|
| 130 |
|
| 131 |
|
|
|
|
| 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 |
|
|
|
|
| 14 |
print(client.heartbeat())
|
| 15 |
print(client.get_version())
|
| 16 |
print(client.list_collections())
|
| 17 |
+
|
| 18 |
from chromadb.utils import embedding_functions
|
| 19 |
default_ef = embedding_functions.DefaultEmbeddingFunction()
|
| 20 |
+
sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="T-Systems-onsite/cross-en-de-roberta-sentence-transformer")
|
| 21 |
|
| 22 |
collection = client.get_collection(name="chromatsc", embedding_function=sentence_transformer_ef)
|
| 23 |
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
def format_prompt(message, history):
|
| 28 |
+
prompt = f"[INST] {message} [/INST]"
|
| 29 |
+
return prompt
|
| 30 |
+
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def response(prompt, history, selected_option, temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0):
|
| 33 |
temperature = float(temperature)
|
|
|
|
| 51 |
combination = zip(results, dists)
|
| 52 |
combination = [' '.join(triplets) for triplets in combination]
|
| 53 |
if len(results) > 1:
|
| 54 |
+
addon = "Bitte berücksichtige bei deiner Antwort ausschießlich 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)
|
| 55 |
system = "Du heißt Avah und bist ein deutschsprachiges KI-basiertes Wahlhilfe Beratungssystem zum Wahl-O-Maten für die Bundestagswahl 2021. Du nimmst selber keine eigene politische Postion ein!" + addon + "\n\nUser-Anliegen:"
|
| 56 |
+
if selected_option == "Keine These ausgewählt":
|
| 57 |
+
selected_option = " "
|
| 58 |
else:
|
| 59 |
+
selected_option = "Die Nutzer Frage bezieht sich auf folgende Wahl-O-Mat These: " + selected_option
|
| 60 |
formatted_prompt = format_prompt(system + "\n" + selected_option + "\n" + prompt, history)
|
| 61 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 62 |
output = ""
|
|
|
|
| 104 |
'Der gesetzliche Mindestlohn soll spätestens im Jahr 2022 auf mindestens 12 Euro erhöht werden.',
|
| 105 |
'Der Flugverkehr soll höher besteuert werden.',
|
| 106 |
'Unternehmen sollen selbst entscheiden, ob sie ihren Beschäftigten das Arbeiten im Homeoffice erlauben.']
|
|
|
|
| 107 |
|
| 108 |
with gr.Blocks() as demo:
|
| 109 |
chatbot = gr.Chatbot(value=[[None, "Hallo mein Name ist Avah (Artificial Voting Advice Helper), deine interaktive Hilfe zum Wahl-O-Maten für die Bundestagswahl 2021. Wenn du Fragen zu Thesen der Wahlhilfe hast, wähle gerne die besagt These aus. Ansonsten kannst du mir auch unabhängig von bestimmten Thesen Fragen stellen."]], render_markdown=True)
|
|
|
|
| 111 |
textbox = gr.Textbox(label="Your Question")
|
| 112 |
|
| 113 |
def combined_response(prompt, history, dropdown_value):
|
| 114 |
+
answer = response(prompt, history, dropdown_value)
|
| 115 |
+
return history + [[prompt, answer]]
|
| 116 |
|
| 117 |
submit_button = gr.Button("Submit")
|
| 118 |
|
|
|
|
| 122 |
outputs=chatbot,
|
| 123 |
)
|
| 124 |
|
| 125 |
+
demo.launch()
|
| 126 |
|
|
|
|
| 127 |
print("Interface up and running!")
|
| 128 |
|
| 129 |
|