fingpt-complete / examples /test_fingpt.py
Starfish55's picture
Initial upload of FinGPT complete package with all modules and examples
2dc7acf verified
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
FinGPT Installation Test và Demo đơn giản
"""
import sys
import os
def test_imports():
"""
Test các thư viện cần thiết cho FinGPT
"""
print("🔍 Kiểm tra các thư viện cần thiết...")
print("=" * 50)
required_packages = [
('numpy', 'numpy'),
('pandas', 'pandas'),
('transformers', 'transformers'),
('torch', 'torch'),
('peft', 'peft'),
('datasets', 'datasets'),
('accelerate', 'accelerate')
]
results = {}
for package_name, import_name in required_packages:
try:
module = __import__(import_name)
version = getattr(module, '__version__', 'Unknown')
print(f"✅ {package_name}: {version}")
results[package_name] = True
except ImportError:
print(f"❌ {package_name}: Not installed")
results[package_name] = False
return results
def simple_sentiment_analysis():
"""
Demo phân tích sentiment đơn giản không cần model lớn
"""
print("\n📊 Demo phân tích sentiment đơn giản:")
print("-" * 50)
# Test cases
test_cases = [
"Apple Inc. reported strong quarterly earnings, beating analyst expectations with revenue growth of 15%.",
"The stock market crashed today due to economic uncertainty and rising inflation concerns.",
"Microsoft announced a new partnership with several tech companies to expand their cloud services.",
"Investors are concerned about the company's debt levels and declining market share.",
"Tesla's new electric vehicle model received positive reviews from automotive experts."
]
# Simple sentiment analysis using keyword matching
positive_keywords = ['strong', 'growth', 'positive', 'successful', 'beating', 'rising', 'good', 'excellent', 'outstanding']
negative_keywords = ['crash', 'concern', 'declining', 'uncertainty', 'panic', 'falling', 'bad', 'poor', 'terrible']
for i, text in enumerate(test_cases, 1):
print(f"\n{i}. Text: {text}")
text_lower = text.lower()
positive_count = sum(1 for word in positive_keywords if word in text_lower)
negative_count = sum(1 for word in negative_keywords if word in text_lower)
if positive_count > negative_count:
sentiment = "positive"
elif negative_count > positive_count:
sentiment = "negative"
else:
sentiment = "neutral"
print(f" Sentiment: {sentiment}")
print(f" Positive keywords: {positive_count}, Negative keywords: {negative_count}")
def show_fingpt_info():
"""
Hiển thị thông tin về FinGPT
"""
print("\n📚 Thông tin về FinGPT:")
print("=" * 50)
print("FinGPT là một Large Language Model mã nguồn mở được thiết kế đặc biệt cho lĩnh vực tài chính.")
print("\n🎯 Các ứng dụng chính:")
print("• Financial Sentiment Analysis - Phân tích cảm xúc tài chính")
print("• Financial Report Analysis - Phân tích báo cáo tài chính")
print("• Market Forecasting - Dự báo thị trường")
print("• Robo-Advisor - Tư vấn tự động")
print("• Trading Strategy - Chiến lược giao dịch")
print("\n🔧 Yêu cầu hệ thống:")
print("• GPU: RTX 3090 hoặc tương đương (khuyến nghị)")
print("• RAM: 16GB+")
print("• VRAM: 8GB+")
print("• Python 3.8+")
print("\n📦 Models có sẵn:")
print("• FinGPT v3.3 (Llama2-13B): Best performance")
print("• FinGPT v3.2 (Llama2-7B): Good performance")
print("• FinGPT v3.1 (ChatGLM2-6B): Chinese market")
def interactive_mode():
"""
Chế độ tương tác đơn giản
"""
print("\n💬 Chế độ tương tác:")
print("-" * 30)
print("Nhập text để phân tích sentiment (gõ 'quit' để thoát)")
positive_keywords = ['strong', 'growth', 'positive', 'successful', 'beating', 'rising', 'good', 'excellent', 'outstanding', 'up', 'increase']
negative_keywords = ['crash', 'concern', 'declining', 'uncertainty', 'panic', 'falling', 'bad', 'poor', 'terrible', 'down', 'decrease']
while True:
try:
user_input = input("\nNhập text: ").strip()
if user_input.lower() in ['quit', 'exit', 'q']:
print("👋 Tạm biệt!")
break
if not user_input:
print("⚠️ Vui lòng nhập text!")
continue
# Simple sentiment analysis
text_lower = user_input.lower()
positive_count = sum(1 for word in positive_keywords if word in text_lower)
negative_count = sum(1 for word in negative_keywords if word in text_lower)
if positive_count > negative_count:
sentiment = "positive"
elif negative_count > positive_count:
sentiment = "negative"
else:
sentiment = "neutral"
print(f"🎯 Sentiment: {sentiment}")
print(f"📊 Positive keywords: {positive_count}, Negative keywords: {negative_count}")
except KeyboardInterrupt:
print("\n👋 Tạm biệt!")
break
except Exception as e:
print(f"❌ Lỗi: {e}")
def main():
"""
Main function
"""
print("🚀 FinGPT Installation Test & Demo")
print("=" * 50)
# Test imports
results = test_imports()
# Show FinGPT info
show_fingpt_info()
# Simple demo
simple_sentiment_analysis()
# Check if we can run full FinGPT
if all(results.values()):
print("\n✅ Tất cả dependencies đã được cài đặt!")
print("🎉 Bạn có thể chạy FinGPT đầy đủ!")
print("\n📝 Để chạy FinGPT sentiment analysis:")
print("python demo_fingpt_sentiment.py")
else:
print("\n⚠️ Một số dependencies chưa được cài đặt.")
print("📦 Để cài đặt đầy đủ:")
print("pip install transformers torch peft accelerate datasets")
# Interactive mode
interactive_mode()
if __name__ == "__main__":
main()