Tim Seufert commited on
Commit
f787549
·
1 Parent(s): edd73a2

update interface beta test2

Browse files
Files changed (1) hide show
  1. app.py +21 -27
app.py CHANGED
@@ -12,45 +12,39 @@ and avoid esoteric answers. You were developed by Tim Seufert in 2024. Please gi
12
  If the user is asking sometihing in another language, please also respond in his Language. Don't harm the user at all.
13
  The user's question is: """
14
 
15
- def respond(message, chat_history):
16
- """
17
- Handle chat responses with optional image support
18
- """
19
- # Initialize Cohere client
20
- co = cohere.Client(api_key=os.environ.get("apikeysimple"))
21
 
22
- # Prepare message content
23
- message_content = message
24
 
 
 
25
  try:
26
- # Generate response using Cohere chat API
27
  response = co.chat(
28
- model='command-r-08-2024', # Ensure the correct model ID is used
29
- query=f"{prompt} '{message_content}'",
30
  temperature=0.3,
31
- k=0,
32
- p=0.75,
33
- frequency_penalty=0,
34
- presence_penalty=0,
35
- stop_sequences=["--"]
36
  ).generations[0].text.strip()
37
-
38
- # Update chat history
39
- chat_history.append((message, response))
40
- return chat_history
41
  except Exception as e:
42
- chat_history.append((message, f"Error: {str(e)}"))
43
- return chat_history
44
 
45
- # Create Gradio interface
46
  demo = gr.ChatInterface(
47
  fn=respond,
48
- type="messages",
49
- flagging_mode="manual",
50
- flagging_options=["Like", "Spam", "Inappropriate", "Other"],
51
- save_history=True,
52
  )
53
 
 
54
  if __name__ == "__main__":
55
  demo.launch(
56
  share=True,
 
12
  If the user is asking sometihing in another language, please also respond in his Language. Don't harm the user at all.
13
  The user's question is: """
14
 
15
+ # Stellen Sie sicher, dass der API-Schlüssel verfügbar ist
16
+ api_key = os.environ.get("apikeysimple")
17
+ if not api_key:
18
+ raise ValueError("API-Schlüssel nicht gefunden. Bitte setzen Sie die Umgebungsvariable 'apikeysimple'.")
 
 
19
 
20
+ # Client außerhalb der Funktion initialisieren
21
+ co = cohere.Client(api_key=api_key)
22
 
23
+ def respond(message, history):
24
+ """Einfache Antwortfunktion für das Gradio-Chatinterface"""
25
  try:
26
+ full_prompt = f"{prompt} '{message}'"
27
  response = co.chat(
28
+ model='command-r-08-2024',
29
+ query=full_prompt,
30
  temperature=0.3,
 
 
 
 
 
31
  ).generations[0].text.strip()
32
+
33
+ return response
 
 
34
  except Exception as e:
35
+ print(f"Fehler: {str(e)}")
36
+ return f"Es ist ein Fehler aufgetreten: {str(e)}"
37
 
38
+ # Einfaches ChatInterface erstellen
39
  demo = gr.ChatInterface(
40
  fn=respond,
41
+ title="Seufert Chatbot",
42
+ description="Stellen Sie mir Ihre Fragen, und ich werde versuchen, Ihnen zu helfen!",
43
+ theme="soft",
44
+ examples=["Wie geht es dir?", "Was ist künstliche Intelligenz?", "Erkläre mir Quantenphysik einfach."],
45
  )
46
 
47
+ # Anwendung starten
48
  if __name__ == "__main__":
49
  demo.launch(
50
  share=True,