Spaces:
Sleeping
Sleeping
Tim Seufert
commited on
Commit
·
12b8f6d
1
Parent(s):
fa3ed48
updateback
Browse files
app.py
CHANGED
@@ -18,68 +18,45 @@ api_key = os.environ.get("apikeysimple")
|
|
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',
|
37 |
-
message=f"{prompt} '{message}
|
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 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
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__":
|
|
|
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 |
+
#(c) Tim Seufert 2024
|
53 |
+
#title="TimSeufert Chatbot",
|
54 |
+
title="SimplestMachine",
|
55 |
+
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",
|
56 |
+
theme="soft",
|
57 |
+
examples=["Wie geht es dir?", "Was ist künstliche Intelligenz?", "Erkläre mir Quantenphysik einfach."],
|
58 |
+
#description2="SimplestMachine hat keinen Zugriff auf echtzeitinformationen. AI kann fehler machen.",
|
59 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Anwendung starten
|
62 |
if __name__ == "__main__":
|