Update app.py
Browse files
app.py
CHANGED
|
@@ -199,7 +199,19 @@ def process_image(image_path, prompt):
|
|
| 199 |
"max_tokens": 300
|
| 200 |
}
|
| 201 |
return headers, payload
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
###################################################
|
| 205 |
#Funktion von Gradio aus, die den dort eingegebenen Prompt annimmt und weiterverarbeitet
|
|
@@ -288,6 +300,41 @@ def generate_text_zu_bild(file, prompt, k, rag_option, chatbot):
|
|
| 288 |
result = data['choices'][0]['message']['content']
|
| 289 |
return result
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
####################################################
|
| 292 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 293 |
#mit oder ohne RAG möglich
|
|
|
|
| 199 |
"max_tokens": 300
|
| 200 |
}
|
| 201 |
return headers, payload
|
| 202 |
+
|
| 203 |
+
##################################################
|
| 204 |
+
#openassistant um uploaded Files zu analysieren
|
| 205 |
+
def create_assistant(prompt, file):
|
| 206 |
+
client = OpenAI()
|
| 207 |
+
assistant = client.beta.assistants.create(name="File Analysator",instructions=template, model="gpt-4-1106-preview",)
|
| 208 |
+
thread = client.beta.threads.create()
|
| 209 |
+
file_neu = client.files.create(file=open(file,"rb",),purpose="assistants",)
|
| 210 |
+
# Update Assistant
|
| 211 |
+
assistant = client.beta.assistants.update(assistant.id,tools=[{"type": "code_interpreter"}, {"type": "retrieval"}],file_ids=[file_neu.id],)
|
| 212 |
+
thread, run = create_thread_and_run(prompt)
|
| 213 |
+
run = wait_on_run(run, thread)
|
| 214 |
+
return get_response(thread))
|
| 215 |
|
| 216 |
###################################################
|
| 217 |
#Funktion von Gradio aus, die den dort eingegebenen Prompt annimmt und weiterverarbeitet
|
|
|
|
| 300 |
result = data['choices'][0]['message']['content']
|
| 301 |
return result
|
| 302 |
|
| 303 |
+
|
| 304 |
+
##################################################
|
| 305 |
+
#zu einem Bild und Text-Prompt eine Analyse generieren
|
| 306 |
+
def generate_text_zu_doc(file, prompt, k, rag_option, chatbot):
|
| 307 |
+
global splittet
|
| 308 |
+
print("text mit doc ..............................")
|
| 309 |
+
prompt_neu = prompt
|
| 310 |
+
if (rag_option == "An"):
|
| 311 |
+
print("Doc mit RAG..............................")
|
| 312 |
+
#muss nur einmal ausgeführt werden...
|
| 313 |
+
if not splittet:
|
| 314 |
+
splits = document_loading_splitting()
|
| 315 |
+
document_storage_chroma(splits)
|
| 316 |
+
db = document_retrieval_chroma2()
|
| 317 |
+
#mit RAG:
|
| 318 |
+
neu_text_mit_chunks = rag_chain2(prompt, db, k)
|
| 319 |
+
#für Chat LLM:
|
| 320 |
+
#prompt = generate_prompt_with_history_openai(neu_text_mit_chunks, history)
|
| 321 |
+
#als reiner prompt:
|
| 322 |
+
prompt_neu = generate_prompt_with_history(neu_text_mit_chunks, chatbot)
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
create_assistant(prompt_neu, file)
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
headers, payload = process_image(file, prompt_neu)
|
| 330 |
+
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
| 331 |
+
#als json ausgeben
|
| 332 |
+
data = response.json()
|
| 333 |
+
# Den "content" auswählen, da dort die Antwort der Ki enthalten ist
|
| 334 |
+
result = data['choices'][0]['message']['content']
|
| 335 |
+
return result
|
| 336 |
+
|
| 337 |
+
|
| 338 |
####################################################
|
| 339 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 340 |
#mit oder ohne RAG möglich
|