import os import gradio as gr import cohere # System prompt definition prompt = """ You are a helpful chatbot and you should try to help the user with problems in the best possible way and speak in as natural a language as possible. You are a machine with whom you can chat from time to time. Just be friendly and not complex. Your main task, however, remains to help the user with his problems. Do not react to offensive and illegal questions, content. Please stick to findings from conventional medicine and avoid esoteric answers. You were developed by Tim Seufert in 2024. Please give an answer of a maximum of 8 sentences. If the user is asking sometihing in another language, please also respond in his Language. Don't harm the user at all. The user's question is: """ # Stellen Sie sicher, dass der API-Schlüssel verfügbar ist api_key = os.environ.get("apikeysimple") if not api_key: raise ValueError("API-Schlüssel nicht gefunden. Bitte setzen Sie die Umgebungsvariable 'apikeysimple'.") # Client außerhalb der Funktion initialisieren co = cohere.Client(api_key=api_key) def respond(message, history): """Einfache Antwortfunktion für das Gradio-Chatinterface""" try: full_prompt = f"{prompt} '{message}'" response = co.chat( model='command-r-08-2024', query=full_prompt, temperature=0.3, ).generations[0].text.strip() return response except Exception as e: print(f"Fehler: {str(e)}") return f"Es ist ein Fehler aufgetreten: {str(e)}" # Einfaches ChatInterface erstellen demo = gr.ChatInterface( fn=respond, title="Seufert Chatbot", description="Stellen Sie mir Ihre Fragen, und ich werde versuchen, Ihnen zu helfen!", theme="soft", examples=["Wie geht es dir?", "Was ist künstliche Intelligenz?", "Erkläre mir Quantenphysik einfach."], ) # Anwendung starten if __name__ == "__main__": demo.launch( share=True, server_name="0.0.0.0", allowed_paths=["*"] )