Tim Seufert commited on
Commit
9dd2467
·
1 Parent(s): c6ff117

visionbetaupdate

Browse files
Files changed (1) hide show
  1. app.py +41 -17
app.py CHANGED
@@ -18,44 +18,68 @@ api_key = os.environ.get("apikeysimple")
18
  # Client außerhalb der Funktion initialisieren
19
  co = cohere.Client(api_key=api_key)
20
 
 
 
 
21
  def respond(message, history):
22
  """Einfache Antwortfunktion für das Gradio-Chatinterface"""
 
23
  try:
 
 
 
 
 
 
24
 
25
  stream = co.chat_stream(
26
- model='command-r-plus-08-2024',
27
- message=f"{prompt} '{message}'",
28
  temperature=0.3,
29
- chat_history=[], # Consider using chat_history for context
30
  prompt_truncation='AUTO',
31
  connectors=[{"id": "web-search"}]
32
  )
33
- # Collect response from stream
34
  response = "".join([
35
  event.text
36
  for event in stream
37
  if event.event_type == "text-generation"
38
  ])
39
 
40
- # Update chat history
41
- #history.append((message, response))
42
- #return "", history
43
  return response
44
 
45
  except Exception as e:
46
  print(f"Fehler: {str(e)}")
47
  return f"Es ist ein Fehler aufgetreten: {str(e)}"
48
 
49
- # Einfaches ChatInterface erstellen
50
- demo = gr.ChatInterface(
51
- fn=respond,
52
- #title="TimSeufert Chatbot",
53
- title="SimplestMachine",
54
- description="Stellen Sie mir Ihre Fragen, und ich werde versuchen, Ihnen zu helfen!-- SimplestMachine hat keinen Zugriff auf echtzeitinformationen. AI kann fehler machen. -- Tim Seufert",
55
- theme="soft",
56
- examples=["Wie geht es dir?", "Was ist künstliche Intelligenz?", "Erkläre mir Quantenphysik einfach."],
57
- #description2="SimplestMachine hat keinen Zugriff auf echtzeitinformationen. AI kann fehler machen.",
58
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  # Anwendung starten
61
  if __name__ == "__main__":
 
18
  # Client außerhalb der Funktion initialisieren
19
  co = cohere.Client(api_key=api_key)
20
 
21
+ # Globale Variable für das aktuelle Bild
22
+ current_image = None
23
+
24
  def respond(message, history):
25
  """Einfache Antwortfunktion für das Gradio-Chatinterface"""
26
+ global current_image
27
  try:
28
+ # Bildkontext hinzufügen, wenn ein Bild vorhanden ist
29
+ image_context = ""
30
+ if current_image:
31
+ image_context = "\nEin Bild wurde hochgeladen. Bitte beschreibe und analysiere dieses Bild: " + current_image
32
+ # Bild zurücksetzen nach Verwendung
33
+ current_image = None
34
 
35
  stream = co.chat_stream(
36
+ model='command-r-plus-08-2024', # Hier ggf. ein Vision-Modell verwenden
37
+ message=f"{prompt} '{message}{image_context}'",
38
  temperature=0.3,
39
+ chat_history=[],
40
  prompt_truncation='AUTO',
41
  connectors=[{"id": "web-search"}]
42
  )
43
+
44
  response = "".join([
45
  event.text
46
  for event in stream
47
  if event.event_type == "text-generation"
48
  ])
49
 
 
 
 
50
  return response
51
 
52
  except Exception as e:
53
  print(f"Fehler: {str(e)}")
54
  return f"Es ist ein Fehler aufgetreten: {str(e)}"
55
 
56
+ def set_image(image):
57
+ """Speichert das hochgeladene Bild global"""
58
+ global current_image
59
+ current_image = image
60
+ return "Bild wurde hochgeladen! Es wird mit Ihrer nächsten Nachricht verarbeitet."
61
+
62
+ # Kombiniertes Interface mit Blocks
63
+ with gr.Blocks() as demo:
64
+ # ChatInterface oben
65
+ chat_interface = gr.ChatInterface(
66
+ fn=respond,
67
+ #(c)Tim Seufert 2024
68
+ title="SimplestMachine",
69
+ description="Stellen Sie mir Ihre Fragen, und ich werde versuchen, Ihnen zu helfen!-- SimplestMachine hat keinen Zugriff auf echtzeitinformationen. AI kann fehler machen.",
70
+ theme="soft",
71
+ examples=["Wie geht es dir?", "Was ist künstliche Intelligenz?", "Erkläre mir Quantenphysik einfach."],
72
+ )
73
+
74
+ # Bildupload-Bereich unten mit Accordion
75
+ with gr.Accordion("Bild hochladen", open=False):
76
+ with gr.Row():
77
+ image_input = gr.Image(type="filepath", label="Bild für die Analyse")
78
+ upload_button = gr.Button("Bild hochladen")
79
+ image_status = gr.Textbox(label="Status", interactive=False)
80
+
81
+ # Verknüpfen des Upload-Buttons mit der set_image-Funktion
82
+ upload_button.click(fn=set_image, inputs=image_input, outputs=image_status)
83
 
84
  # Anwendung starten
85
  if __name__ == "__main__":