File size: 3,668 Bytes
2dc7acf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""

FinGPT Simple Demo - Sử dụng model nhỏ hơn để test

"""

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import warnings
warnings.filterwarnings("ignore")

def simple_sentiment_demo():
    """

    Demo đơn giản sử dụng model có sẵn

    """
    print("🚀 FinGPT Simple Demo")
    print("=" * 40)
    
    # Sử dụng model nhỏ hơn để test
    model_name = "microsoft/DialoGPT-medium"
    
    try:
        print("📝 Đang tải tokenizer...")
        tokenizer = AutoTokenizer.from_pretrained(model_name)
        
        print("🧠 Đang tải model...")
        model = AutoModelForCausalLM.from_pretrained(model_name)
        
        print("✅ Model đã được tải thành công!")
        
        # Test cases
        test_texts = [
            "Apple stock is rising today",
            "Market crash causes panic",
            "New product launch successful"
        ]
        
        print("\n📊 Test sentiment analysis:")
        print("-" * 40)
        
        for i, text in enumerate(test_texts, 1):
            print(f"\n{i}. Text: {text}")
            
            # Simple sentiment analysis using text patterns
            text_lower = text.lower()
            if any(word in text_lower for word in ['rising', 'successful', 'good', 'positive', 'up']):
                sentiment = "positive"
            elif any(word in text_lower for word in ['crash', 'panic', 'down', 'negative', 'falling']):
                sentiment = "negative"
            else:
                sentiment = "neutral"
            
            print(f"   Sentiment: {sentiment}")
        
        return True
        
    except Exception as e:
        print(f"❌ Lỗi: {e}")
        return False

def test_fingpt_installation():
    """

    Test xem FinGPT có thể import được không

    """
    print("\n🔍 Kiểm tra FinGPT installation...")
    
    try:
        # Test import các thư viện cần thiết
        import transformers
        print(f"✅ Transformers version: {transformers.__version__}")
        
        import peft
        print(f"✅ PEFT version: {peft.__version__}")
        
        import torch
        print(f"✅ PyTorch version: {torch.__version__}")
        
        if torch.cuda.is_available():
            print(f"✅ CUDA available: {torch.cuda.get_device_name(0)}")
        else:
            print("⚠️ CUDA không khả dụng, sẽ sử dụng CPU")
        
        return True
        
    except ImportError as e:
        print(f"❌ Import error: {e}")
        return False

def main():
    """

    Main function

    """
    # Test installation
    if not test_fingpt_installation():
        print("\n❌ FinGPT installation có vấn đề!")
        return
    
    # Simple demo
    print("\n" + "=" * 50)
    simple_sentiment_demo()
    
    print("\n" + "=" * 50)
    print("📝 Hướng dẫn sử dụng FinGPT:")
    print("1. Để sử dụng model đầy đủ, cần GPU với ít nhất 8GB VRAM")
    print("2. Model FinGPT sentiment analysis có sẵn trên HuggingFace")
    print("3. Có thể sử dụng CPU nhưng sẽ chậm hơn")
    print("4. Xem thêm tại: https://huggingface.co/FinGPT")
    
    print("\n🎯 Các ứng dụng FinGPT:")
    print("- Financial Sentiment Analysis")
    print("- Financial Report Analysis") 
    print("- Market Forecasting")
    print("- Robo-Advisor")
    print("- Trading Strategy")

if __name__ == "__main__":
    main()