Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -87,7 +87,6 @@ def process_pdf(file):
|
|
87 |
ids=[file.name] # Use the filename as the unique ID
|
88 |
)
|
89 |
|
90 |
-
|
91 |
return f"PDF wurde erfolgreich in ChromaDB gespeichert."
|
92 |
|
93 |
def search_similar_documents(prompt):
|
@@ -97,7 +96,7 @@ def search_similar_documents(prompt):
|
|
97 |
# Führe die Ähnlichkeitssuche durch
|
98 |
results = collection.query(
|
99 |
query_embeddings=[query_embedding],
|
100 |
-
n_results=
|
101 |
)
|
102 |
|
103 |
# Formatiere die Ergebnisse
|
@@ -105,6 +104,56 @@ def search_similar_documents(prompt):
|
|
105 |
for i, doc in enumerate(results["documents"][0]):
|
106 |
metadata = results["metadatas"][0][i]
|
107 |
filename = metadata["filename"]
|
108 |
-
formatted_results.append(f"
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
ids=[file.name] # Use the filename as the unique ID
|
88 |
)
|
89 |
|
|
|
90 |
return f"PDF wurde erfolgreich in ChromaDB gespeichert."
|
91 |
|
92 |
def search_similar_documents(prompt):
|
|
|
96 |
# Führe die Ähnlichkeitssuche durch
|
97 |
results = collection.query(
|
98 |
query_embeddings=[query_embedding],
|
99 |
+
n_results=3
|
100 |
)
|
101 |
|
102 |
# Formatiere die Ergebnisse
|
|
|
104 |
for i, doc in enumerate(results["documents"][0]):
|
105 |
metadata = results["metadatas"][0][i]
|
106 |
filename = metadata["filename"]
|
107 |
+
formatted_results.append(f"{doc}\n")
|
108 |
+
|
109 |
+
ergebnis = f"{''.join(formatted_results)}"
|
110 |
+
ergebnis = gr.Markdown(ergebnis)
|
111 |
+
return ergebnis
|
112 |
+
|
113 |
+
|
114 |
+
with gr.Blocks() as chat:
|
115 |
+
gr.Markdown("### Ask the RKI Files", elem_classes="tab-header")
|
116 |
+
with gr.Row():
|
117 |
+
llm_output = gr.Textbox(label="LLM Answer")
|
118 |
+
with gr.Row():
|
119 |
+
llm_prompt_input = gr.Textbox(label="Frage an das LLM", placeholder="Gib eine Frage ein")
|
120 |
+
llm_submit_button = gr.Button("send")
|
121 |
+
llm_submit_button.click(ask_llm, inputs=llm_prompt_input, outputs=llm_output)
|
122 |
+
|
123 |
+
with gr.Blocks() as upload:
|
124 |
+
gr.Markdown("### File upload", elem_classes="tab-header")
|
125 |
+
with gr.Row():
|
126 |
+
file_input = gr.File(label="Wähle eine PDF-Datei aus", type="filepath")
|
127 |
+
upload_output = gr.Textbox(label="Upload Status")
|
128 |
+
with gr.Row():
|
129 |
+
submit_button = gr.Button("upload")
|
130 |
+
submit_button.click(process_pdf, inputs=file_input, outputs=upload_output)
|
131 |
+
|
132 |
+
with gr.Blocks() as suche:
|
133 |
+
gr.Markdown("### Datenbank durchsuchen", elem_classes="tab-header")
|
134 |
+
with gr.Row():
|
135 |
+
prompt_input = gr.Textbox(label="Suche nach ähnlichen Dokumenten", placeholder="Gib einen Suchbegriff ein")
|
136 |
+
with gr.Row():
|
137 |
+
search_output = gr.Textbox(label="Ähnliche Dokumente")
|
138 |
+
with gr.Row():
|
139 |
+
search_button = gr.Button("Suchen")
|
140 |
+
search_button.click(search_similar_documents, inputs=prompt_input, outputs=search_output)
|
141 |
+
|
142 |
+
#optional, Spracheingabe
|
143 |
+
with gr.Blocks() as speech:
|
144 |
+
gr.Markdown("### Highspeed Voicebot", elem_classes="tab-header")
|
145 |
+
with gr.Row():
|
146 |
+
sr_outputs = gr.Textbox(label="Antwort")
|
147 |
+
with gr.Row():
|
148 |
+
sr_inputs = gr.Microphone(type="filepath")
|
149 |
+
sr_inputs.change(transcribe_audio, inputs=sr_inputs, outputs=sr_outputs)
|
150 |
+
|
151 |
+
# Erstelle die Gradio-Schnittstelle
|
152 |
+
with gr.Blocks() as demo:
|
153 |
+
gr.TabbedInterface(
|
154 |
+
[chat, upload, suche],
|
155 |
+
["Chat", "Upload", "Suche"]
|
156 |
+
)
|
157 |
+
|
158 |
+
# Starte die Gradio-Anwendung
|
159 |
+
demo.launch()
|