alexkueck commited on
Commit
191b138
1 Parent(s): c8af80b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -47
app.py CHANGED
@@ -364,22 +364,38 @@ def umwandeln_fuer_anzeige(image):
364
 
365
  def generate_auswahl(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
366
  if (prompt.find('zeichnen') != -1):
367
- generate_bild(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
 
 
 
 
 
 
 
368
  else:
369
- generate_text(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
  def generate_bild(prompt, history,):
372
  data = {"inputs": prompt}
373
  response = requests.post(API_URL, headers=HEADERS, json=data)
374
  print("fertig Bild")
375
  result = response.content
376
- #Bild ausgeben
377
- image = Image.open(io.BytesIO(result))
378
-
379
- history[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(b64encode(umwandeln_fuer_anzeige(image)).decode('utf-8'))
380
- print("history zeichnen......................")
381
- print(history)
382
- return history, "Fertig: Success"
383
 
384
  def generate_text (prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
385
  global splittet
@@ -414,16 +430,8 @@ def generate_text (prompt, file, history, rag_option, model_option, openai_api_k
414
  ###########################
415
  if (model_option == "OpenAI"):
416
  #Anfrage an OpenAI ----------------------------
417
- if (prompt.find('zeichnen') != -1):
418
- #print("OpenAI zeichnen.......................")
419
- #llm = ChatOpenAI(model_name = MODEL_NAME_OAI_ZEICHNEN, openai_api_key = openai_api_key, temperature=temperature)#, top_p = top_p)
420
- data = {"inputs": prompt}
421
- response = requests.post(API_URL, headers=HEADERS, json=data)
422
- print("fertig Bild")
423
- else:
424
- print("OpenAI normal.......................")
425
- llm = ChatOpenAI(model_name = MODEL_NAME, openai_api_key = openai_api_key, temperature=temperature)#, top_p = top_p)
426
-
427
  print("openAI")
428
  else:
429
  #oder an Hugging Face --------------------------
@@ -448,41 +456,15 @@ def generate_text (prompt, file, history, rag_option, model_option, openai_api_k
448
  result = rag_chain(llm, history_text_und_prompt, db)
449
  else:
450
  print("LLM aufrufen ohne RAG: ...........")
451
- if (prompt.find('zeichnen') != -1):
452
- result = response.content
453
- else:
454
- print("ganz normale Ausführung.........................")
455
- result = llm_chain(llm, history_text_und_prompt)
456
 
457
 
458
  except Exception as e:
459
  raise gr.Error(e)
460
 
 
461
 
462
- if (prompt.find('zeichnen') != -1):
463
- #Bild ausgeben
464
- image = Image.open(io.BytesIO(result))
465
 
466
- history[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(b64encode(umwandeln_fuer_anzeige(image)).decode('utf-8'))
467
- print("history zeichnen......................")
468
- print(history)
469
- return history, "Fertig: Success"
470
- else:
471
- #Antwort als Stream ausgeben... wenn Textantwort gefordert
472
- print("history vor Zusatz...........")
473
- print(history)
474
- history[-1][1] = ""
475
- for character in result:
476
- history[-1][1] += character
477
- time.sleep(0.03)
478
- yield history, "Generating"
479
- if shared_state.interrupted:
480
- shared_state.recover()
481
- try:
482
- yield history, "Stop: Success"
483
- return
484
- except:
485
- pass
486
 
487
  ################################################
488
  #GUI
 
364
 
365
  def generate_auswahl(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
366
  if (prompt.find('zeichnen') != -1):
367
+ result = generate_bild(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
368
+ #Bild ausgeben
369
+ image = Image.open(io.BytesIO(result))
370
+
371
+ history[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(b64encode(umwandeln_fuer_anzeige(image)).decode('utf-8'))
372
+ print("history zeichnen......................")
373
+ print(history)
374
+ return history, "Success"
375
  else:
376
+ result = generate_text(prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
377
+ #Antwort als Stream ausgeben... wenn Textantwort gefordert
378
+ print("history vor Zusatz...........")
379
+ print(history)
380
+ history[-1][1] = ""
381
+ for character in result:
382
+ history[-1][1] += character
383
+ time.sleep(0.03)
384
+ yield history, "Generating"
385
+ if shared_state.interrupted:
386
+ shared_state.recover()
387
+ try:
388
+ yield history, "Stop: Success"
389
+ return
390
+ except:
391
+ pass
392
 
393
  def generate_bild(prompt, history,):
394
  data = {"inputs": prompt}
395
  response = requests.post(API_URL, headers=HEADERS, json=data)
396
  print("fertig Bild")
397
  result = response.content
398
+ return result
 
 
 
 
 
 
399
 
400
  def generate_text (prompt, file, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
401
  global splittet
 
430
  ###########################
431
  if (model_option == "OpenAI"):
432
  #Anfrage an OpenAI ----------------------------
433
+ print("OpenAI normal.......................")
434
+ llm = ChatOpenAI(model_name = MODEL_NAME, openai_api_key = openai_api_key, temperature=temperature)#, top_p = top_p)
 
 
 
 
 
 
 
 
435
  print("openAI")
436
  else:
437
  #oder an Hugging Face --------------------------
 
456
  result = rag_chain(llm, history_text_und_prompt, db)
457
  else:
458
  print("LLM aufrufen ohne RAG: ...........")
459
+ result = llm_chain(llm, history_text_und_prompt)
 
 
 
 
460
 
461
 
462
  except Exception as e:
463
  raise gr.Error(e)
464
 
465
+ return result
466
 
 
 
 
467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
 
469
  ################################################
470
  #GUI