Markus Clauss DIRU Vetsuisse
Update to use publicai InferenceClient and change to Ueli from Basel
f6aef1b
| #!/usr/bin/env python3 | |
| """ | |
| Lokaler Test für Apertus Dialekt-Konsil | |
| """ | |
| import os | |
| # Setze HF_TOKEN wenn noch nicht gesetzt | |
| if not os.environ.get('HF_TOKEN'): | |
| token = input("Bitte HF_TOKEN eingeben (hf_...): ") | |
| os.environ['HF_TOKEN'] = token | |
| # Teste zuerst die API-Verbindung | |
| print("🔍 Teste API-Verbindung...") | |
| from huggingface_hub import InferenceClient | |
| try: | |
| client = InferenceClient( | |
| provider="publicai", | |
| api_key=os.environ['HF_TOKEN'] | |
| ) | |
| # Test-Anfrage | |
| completion = client.chat.completions.create( | |
| model="swiss-ai/Apertus-8B-Instruct-2509", | |
| messages=[ | |
| {"role": "user", "content": "Sag Hallo auf Schweizerdeutsch!"} | |
| ], | |
| max_tokens=50 | |
| ) | |
| print("✅ API funktioniert!") | |
| print(f"Test-Antwort: {completion.choices[0].message.content}") | |
| except Exception as e: | |
| print(f"❌ API-Fehler: {e}") | |
| print("Bitte prüfe deinen HF_TOKEN und Zugriff auf Apertus model") | |
| exit(1) | |
| # Starte die App | |
| print("\n🚀 Starte Dialekt-Konsil App...") | |
| print("Öffne http://localhost:7860 im Browser\n") | |
| import app | |
| demo = app.create_interface() | |
| demo.launch(share=False) |