Spaces:
Running
Running
File size: 5,832 Bytes
388aa42 | 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | """
JanSahayak - Multi-Agent Government Intelligence System
Main entry point for the application
"""
import json
import os
from datetime import datetime
from graph.workflow import run_workflow
from agent_io.profiling_io import ProfilingIO
from agent_io.scheme_io import SchemeIO
from agent_io.exam_io import ExamIO
from agent_io.benefit_io import BenefitIO
def save_results(result: dict, output_dir: str = "outputs"):
"""
Save final results to JSON file
Args:
result: Final output dictionary
output_dir: Directory to save results
"""
os.makedirs(output_dir, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{output_dir}/results_{timestamp}.json"
with open(filename, 'w', encoding='utf-8') as f:
json.dump(result, f, indent=2, ensure_ascii=False)
print(f"\n๐พ Results saved to: {filename}")
return filename
def print_summary(result: dict):
"""
Print a formatted summary of results
Args:
result: Final output dictionary
"""
print("\n" + "="*70)
print("๐ JANSAHAYAK - RESULTS SUMMARY")
print("="*70)
# Profile Summary
profile = result.get("user_profile", {})
print("\n๐ค USER PROFILE:")
print("-" * 70)
if isinstance(profile, dict) and "error" not in profile:
for key, value in profile.items():
if key not in ["raw_profile", "user_input"]:
print(f" โข {key.replace('_', ' ').title()}: {value}")
else:
print(" โ ๏ธ Profile extraction failed")
# Scheme Recommendations
print("\n๐๏ธ GOVERNMENT SCHEMES:")
print("-" * 70)
schemes = result.get("scheme_recommendations", "")
if schemes and schemes != "Profile unavailable":
print(schemes[:500] + "..." if len(schemes) > 500 else schemes)
else:
print(" โ ๏ธ No scheme recommendations available")
# Exam Recommendations
print("\n๐ COMPETITIVE EXAMS:")
print("-" * 70)
exams = result.get("exam_recommendations", "")
if exams and exams != "Profile unavailable":
print(exams[:500] + "..." if len(exams) > 500 else exams)
else:
print(" โ ๏ธ No exam recommendations available")
# Benefit Analysis
print("\n๐ฐ MISSED BENEFITS ANALYSIS:")
print("-" * 70)
benefits = result.get("missed_benefits_analysis", "")
if benefits and benefits != "Insufficient data":
print(benefits[:500] + "..." if len(benefits) > 500 else benefits)
else:
print(" โ ๏ธ Benefit analysis unavailable")
# Errors
errors = result.get("errors", [])
if errors:
print("\nโ ๏ธ ERRORS ENCOUNTERED:")
print("-" * 70)
for error in errors:
print(f" โข {error}")
print("\n" + "="*70)
def interactive_mode():
"""
Interactive mode for user input
"""
print("\n" + "="*70)
print("๐ WELCOME TO JANSAHAYAK")
print("Multi-Agent Government Intelligence System")
print("="*70)
print("\nPlease provide your details for personalized recommendations.")
print("Include information about:")
print(" โข Age, Gender, State of residence")
print(" โข Income, Caste/Category")
print(" โข Education qualification")
print(" โข Employment status")
print(" โข Career interests (for exam recommendations)")
print("\nEnter 'quit' to exit.")
print("-" * 70)
while True:
print("\n๐ Enter your details (or 'quit' to exit):")
# Get multi-line input
lines = []
while True:
line = input()
if line.lower() == 'quit':
print("\n๐ Thank you for using JanSahayak!")
return
if line.lower() == 'done' or (line == '' and lines):
break
lines.append(line)
user_input = '\n'.join(lines)
if not user_input.strip():
print("โ ๏ธ No input provided. Please try again.")
continue
# Run workflow
try:
result = run_workflow(user_input)
# Print summary
print_summary(result)
# Save results
save_results(result)
# Ask if user wants to continue
print("\n" + "-" * 70)
cont = input("Would you like another analysis? (yes/no): ")
if cont.lower() not in ['yes', 'y']:
print("\n๐ Thank you for using JanSahayak!")
break
except Exception as e:
print(f"\nโ Error: {str(e)}")
print("Please try again with different input.")
def file_mode(input_file: str):
"""
Process input from file
Args:
input_file: Path to input text file
"""
try:
with open(input_file, 'r', encoding='utf-8') as f:
user_input = f.read()
print(f"\n๐ Processing input from: {input_file}")
result = run_workflow(user_input)
print_summary(result)
save_results(result)
except FileNotFoundError:
print(f"โ Error: File not found: {input_file}")
except Exception as e:
print(f"โ Error: {str(e)}")
def main():
"""
Main entry point
"""
import sys
if len(sys.argv) > 1:
# File mode
input_file = sys.argv[1]
file_mode(input_file)
else:
# Interactive mode
interactive_mode()
if __name__ == "__main__":
main()
|