Autism_QA / auto_pipe.py
A7m0d's picture
Upload folder using huggingface_hub
712579e verified
#!/usr/bin/env python3
"""
# Process only first 10 questions
python auto_pipe.py questions.csv --samples 10
# Process 50 questions with custom output file
python auto_pipe.py questions.csv --samples 50 --output results.csv
# Create sample CSV with 20 questions and process all
python auto_pipe.py --create-sample --sample-size 20
# Process 5 questions from custom column
python auto_pipe.py questions.csv --column "user_question" --samples 5
# Process all questions (no limit)
python auto_pipe.py questions.csv
"""
import os
import sys
import pandas as pd
from datetime import datetime
# Add the project directory to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import the CSV test runner
from test_runner import run_csv_test, create_sample_csv
def main():
print("πŸ€– Wisal CSV Test Runner")
print("=" * 40)
# Check if CSV file is provided as argument
if len(sys.argv) > 1:
csv_file = sys.argv[1]
if not os.path.exists(csv_file):
print(f"❌ Error: File '{csv_file}' not found")
return
else:
# Create a sample CSV file
print("πŸ“ No CSV file provided. Creating sample questions...")
csv_file = create_sample_csv("assets/qa_data.csv")
print(f"βœ… Sample CSV created: {csv_file}")
# Determine output file
if len(sys.argv) > 3 and sys.argv[2] == "-o":
output_file = sys.argv[3]
else:
base_name = os.path.splitext(csv_file)[0]
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"{base_name}_results_{timestamp}.csv"
print(f"πŸ“₯ Input file: {csv_file}")
print(f"πŸ“€ Output file: {output_file}")
print("πŸš€ Starting test run...\n")
try:
# Run the test
result_file = run_csv_test(csv_file, output_file)
# Show preview of results
print("\nπŸ“Š Results Preview:")
print("-" * 40)
df = pd.read_csv(result_file)
for idx, row in df.iterrows():
status_emoji = "βœ…" if row['status'] == 'success' else "❌"
print(f"{status_emoji} Q{idx+1}: {row['question'][:60]}...")
print(f" ⏱️ Time: {row['total_time_seconds']:.2f}s")
if row['status'] == 'success':
print(f" πŸ’¬ Answer: {row['clean_answer'][:100]}...")
else:
print(f" ❌ Error: {row['error_message']}")
print()
# Summary
successful = len(df[df['status'] == 'success'])
total = len(df)
avg_time = df[df['status'] == 'success']['total_time_seconds'].mean()
print("πŸ“ˆ Summary:")
print(f" Total Questions: {total}")
print(f" Successful: {successful}")
print(f" Failed: {total - successful}")
print(f" Average Time: {avg_time:.2f} seconds")
print(f" Results saved to: {result_file}")
except Exception as e:
print(f"❌ Error running test: {e}")
return
if __name__ == "__main__":
main()