zxc4wewewe commited on
Commit
8a2ad32
Β·
verified Β·
1 Parent(s): c55d722

Create check_models.py

Browse files
Files changed (1) hide show
  1. check_models.py +59 -0
check_models.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from hf_api import HuggingFaceAPI
2
+ import os
3
+ import json
4
+ from datetime import datetime
5
+
6
+ from utils import load_settings, save_settings
7
+
8
+ # Settings paths
9
+ SETTINGS_DIR = os.path.join(os.path.dirname(__file__), 'settings')
10
+ MODELS_SETTINGS_FILE = os.path.join(SETTINGS_DIR, 'models.json')
11
+ FIREBASE_SETTINGS_FILE = os.path.join(SETTINGS_DIR, 'firebase.json')
12
+ APP_SETTINGS_FILE = os.path.join(SETTINGS_DIR, 'app.json')
13
+
14
+ model_settings = load_settings(MODELS_SETTINGS_FILE)
15
+ HF_TOKEN = model_settings.get('huggingfaceToken', '')
16
+
17
+ api = HuggingFaceAPI(token=HF_TOKEN) if HF_TOKEN else None
18
+
19
+ print("Checking available models...")
20
+ print("\n1. Testing text generation models:")
21
+ models = ["meta-llama/Llama-3.2-3B-Instruct", "microsoft/Phi-3-mini-4k-instruct"]
22
+ for model in models:
23
+ try:
24
+ result = api.validate_model(model)
25
+ print(f" {model}: {'βœ… Available' if result['valid'] else '❌ Not available'}")
26
+ except Exception as e:
27
+ print(f" {model}: ❌ Error - {str(e)[:50]}...")
28
+
29
+ print("\n2. Testing translation models:")
30
+ models = ["Helsinki-NLP/opus-mt-en-de", "Helsinki-NLP/opus-mt-en-fr"]
31
+ for model in models:
32
+ try:
33
+ result = api.validate_model(model)
34
+ print(f" {model}: {'βœ… Available' if result['valid'] else '❌ Not available'}")
35
+ if not result['valid'] and 'fallback_models' in result:
36
+ print(f" Fallbacks: {[m['id'] for m in result['fallback_models'][:2]]}")
37
+ except Exception as e:
38
+ print(f" {model}: ❌ Error - {str(e)[:50]}...")
39
+
40
+ print("\n3. Testing Google models:")
41
+ models = ["google/madlad400-3b-mt", "google/translategemma-12b-it"]
42
+ for model in models:
43
+ try:
44
+ result = api.validate_model(model)
45
+ print(f" {model}: {'βœ… Available' if result['valid'] else '❌ Not available'}")
46
+ except Exception as e:
47
+ print(f" {model}: ❌ Error - {str(e)[:50]}...")
48
+
49
+ print("\n4. Testing chat completion with Llama:")
50
+ try:
51
+ messages = [{"role": "user", "content": "Translate 'Hello world' to French"}]
52
+ response = api.chat_completion(
53
+ model="meta-llama/Llama-3.2-3B-Instruct",
54
+ messages=messages,
55
+ max_tokens=100
56
+ )
57
+ print(f" βœ… Chat translation works: {response['choices'][0]['message']['content'][:50]}...")
58
+ except Exception as e:
59
+ print(f" ❌ Chat translation failed: {str(e)[:50]}...")