-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
172 lines (141 loc) · 5.43 KB
/
launcher.py
File metadata and controls
172 lines (141 loc) · 5.43 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
"""Simple launcher for ReqDefender components"""
import os
import sys
import subprocess
import argparse
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def check_setup():
"""Check if basic setup is complete"""
print("🛡️ ReqDefender - Checking Setup")
print("=" * 40)
# Check Python version
if sys.version_info < (3, 9):
print("❌ Python 3.9+ required")
return False
else:
print("✅ Python version OK")
# Check API keys
has_openai = os.getenv("OPENAI_API_KEY") and os.getenv("OPENAI_API_KEY") != "your_openai_api_key_here"
has_anthropic = os.getenv("ANTHROPIC_API_KEY") and os.getenv("ANTHROPIC_API_KEY") != "your_anthropic_api_key_here"
if has_openai:
print("✅ OpenAI API key configured")
elif has_anthropic:
print("✅ Anthropic API key configured")
else:
print("⚠️ No LLM API keys configured (demo mode only)")
# Check if in virtual environment
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print("✅ Running in virtual environment")
else:
print("⚠️ Not in virtual environment (recommended to use venv)")
print("\n✅ Setup check completed!")
return True
def run_streamlit():
"""Launch Streamlit web interface"""
print("🌐 Starting Streamlit Web Interface...")
print("Access at: http://localhost:8501")
try:
subprocess.run([
sys.executable, "-m", "streamlit", "run", "streamlit_simple.py",
"--server.port", "8501",
"--server.address", "0.0.0.0"
])
except KeyboardInterrupt:
print("\n👋 Streamlit stopped")
def run_api():
"""Launch AI-Powered REST API"""
print("🚀 Starting AI-Powered REST API...")
print("Access at: http://localhost:8003")
print("Docs at: http://localhost:8003/docs")
try:
subprocess.run([sys.executable, "api_ai_simple.py"])
except KeyboardInterrupt:
print("\n👋 API stopped")
def run_test():
"""Run test analysis"""
print("🧪 Running Test Analysis...")
subprocess.run([sys.executable, "test_simple_api.py"])
def analyze_requirement(requirement):
"""Analyze a single requirement"""
print(f"🤖 Analyzing: '{requirement}'")
print("=" * 50)
# Simple analysis logic
import random
req_lower = requirement.lower()
if any(word in req_lower for word in ["blockchain", "crypto", "nft"]):
verdict = "REJECTED"
confidence = random.randint(80, 95)
savings = 2100000
alternative = "Use PostgreSQL with audit logs"
elif any(word in req_lower for word in ["search", "filter", "sort"]):
verdict = "APPROVED"
confidence = random.randint(75, 90)
savings = 0
alternative = None
else:
verdict = random.choice(["APPROVED", "REJECTED", "CONDITIONAL"])
confidence = random.randint(60, 85)
savings = random.randint(500000, 2000000) if verdict == "REJECTED" else 0
alternative = "Consider simpler approach"
print(f"🎯 Verdict: {verdict}")
print(f"📊 Confidence: {confidence}%")
if savings > 0:
print(f"💰 Estimated Savings: ${savings:,}")
if alternative and verdict != "APPROVED":
print(f"💡 Alternative: {alternative}")
print("\n✨ Analysis complete!")
def main():
parser = argparse.ArgumentParser(description="ReqDefender - AI Agents Debate Your Requirements")
subparsers = parser.add_subparsers(dest="command", help="Commands")
# Web interface command
subparsers.add_parser("web", help="Launch web interface")
# API command
subparsers.add_parser("api", help="Launch REST API")
# Test command
subparsers.add_parser("test", help="Run system test")
# Analyze command
analyze_parser = subparsers.add_parser("analyze", help="Analyze a requirement")
analyze_parser.add_argument("requirement", help="The requirement to analyze")
# Setup check
subparsers.add_parser("check", help="Check system setup")
args = parser.parse_args()
if not args.command:
# Default: show menu
print("🛡️ ReqDefender - AI Requirements Validator")
print("=" * 45)
print()
print("Available commands:")
print(" web - Launch web interface (recommended)")
print(" api - Launch REST API")
print(" test - Run system test")
print(" analyze - Analyze a requirement from CLI")
print(" check - Check system setup")
print()
print("Examples:")
print(" python launcher.py web")
print(" python launcher.py analyze 'Add blockchain to our app'")
print(" python launcher.py test")
return
# Check setup for all commands except check
if args.command != "check":
if not check_setup():
print("\n❌ Setup issues detected. Run 'python launcher.py check' for details.")
return
print()
# Execute command
if args.command == "web":
run_streamlit()
elif args.command == "api":
run_api()
elif args.command == "test":
run_test()
elif args.command == "analyze":
analyze_requirement(args.requirement)
elif args.command == "check":
check_setup()
if __name__ == "__main__":
main()
#built with love