File size: 2,079 Bytes
2d802f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
import os

# Add current directory to path
sys.path.append(os.getcwd())

from models_loader import loader
import torch
from PIL import Image
import numpy as np

def test_models():
    print("--- Starting Model Verification ---")
    
    # 1. Sentiment
    print("\nTesting Sentiment Analysis...")
    if loader.sentiment_pipeline:
        res = loader.sentiment_pipeline("I love this project!")
        print(f"Result: {res}")
    else:
        print("FAILED: Sentiment pipeline not loaded")

    # 2. QA
    print("\nTesting Question Answering...")
    if loader.qa_pipeline:
        res = loader.qa_pipeline(question="What is this?", context="This is a test.")
        print(f"Result: {res}")
    else:
        print("FAILED: QA pipeline not loaded")

    # 3. Translation
    print("\nTesting Translation (MT-EN-UR)...")
    if loader.translator_pipeline:
        res = loader.translator_pipeline("Hello, how are you?")
        print(f"Result: {res}")
    else:
        print("FAILED: Translation pipeline not loaded")

    # 4. Text Gen
    print("\nTesting Text Generation...")
    if loader.text_gen_pipeline:
        res = loader.text_gen_pipeline("Once upon a time", max_length=20)
        print(f"Result: {res}")
    else:
        print("FAILED: Text Gen pipeline not loaded")

    # 5. ZSL
    print("\nTesting Zero-Shot Learning...")
    if loader.zsl_pipeline:
        res = loader.zsl_pipeline("This is about sports.", candidate_labels=["politics", "sports", "cooking"])
        print(f"Result: {res['labels'][0]}")
    else:
        print("FAILED: ZSL pipeline not loaded")

    # 6. Gender Classifier (Mini)
    print("\nTesting Image Classification (Gender)...")
    if loader.gender_classifier:
        # Create a dummy image
        dummy_img = Image.fromarray(np.uint8(np.random.rand(224,224,3)*255))
        res = loader.gender_classifier(dummy_img)
        print(f"Result: {res}")
    else:
        print("FAILED: Gender classifier pipeline not loaded")

    print("\n--- Verification Complete ---")

if __name__ == "__main__":
    test_models()