File size: 8,249 Bytes
9e7dc23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env python3
"""
Simple client script to test the AI Text Humanizer API
"""

import requests
import json
import time

# Configuration
API_BASE_URL = "http://localhost:8000"

def test_api_connection():
    """Test if the API server is running"""
    try:
        response = requests.get(f"{API_BASE_URL}/health", timeout=5)
        if response.status_code == 200:
            print("βœ… API server is running!")
            return True
        else:
            print(f"❌ API server responded with status {response.status_code}")
            return False
    except requests.exceptions.RequestException as e:
        print(f"❌ Cannot connect to API server: {e}")
        print("πŸ’‘ Make sure to run: python fastapi_server.py")
        return False

def humanize_single_text(text, style="natural", intensity=0.7):
    """Humanize a single piece of text"""
    try:
        payload = {
            "text": text,
            "style": style,
            "intensity": intensity
        }
        
        response = requests.post(
            f"{API_BASE_URL}/humanize",
            json=payload,
            headers={"Content-Type": "application/json"}
        )
        
        if response.status_code == 200:
            return response.json()
        else:
            print(f"❌ API Error: {response.status_code}")
            print(response.text)
            return None
            
    except requests.exceptions.RequestException as e:
        print(f"❌ Request failed: {e}")
        return None

def humanize_batch_texts(texts, style="natural", intensity=0.7):
    """Humanize multiple texts in batch"""
    try:
        payload = {
            "texts": texts,
            "style": style,
            "intensity": intensity
        }
        
        response = requests.post(
            f"{API_BASE_URL}/batch_humanize",
            json=payload,
            headers={"Content-Type": "application/json"}
        )
        
        if response.status_code == 200:
            return response.json()
        else:
            print(f"❌ API Error: {response.status_code}")
            print(response.text)
            return None
            
    except requests.exceptions.RequestException as e:
        print(f"❌ Request failed: {e}")
        return None

def display_result(result):
    """Display humanization result in a formatted way"""
    if not result:
        return
        
    print("\n" + "="*60)
    print("πŸ“ ORIGINAL TEXT:")
    print("-" * 40)
    print(result['original_text'])
    
    print("\n✨ HUMANIZED TEXT:")
    print("-" * 40)
    print(result['humanized_text'])
    
    print(f"\nπŸ“Š STATS:")
    print(f"   β€’ Similarity Score: {result['similarity_score']:.3f}")
    print(f"   β€’ Processing Time: {result['processing_time_ms']:.1f}ms")
    print(f"   β€’ Style: {result['style'].title()}")
    print(f"   β€’ Intensity: {result['intensity']}")
    
    if result['changes_made']:
        print(f"\nπŸ”„ CHANGES MADE:")
        for change in result['changes_made']:
            print(f"   β€’ {change}")
    else:
        print(f"\nπŸ”„ CHANGES MADE: None")

def interactive_mode():
    """Interactive mode for testing"""
    print("\n🎯 Interactive Mode")
    print("Type 'quit' to exit\n")
    
    while True:
        text = input("πŸ“ Enter text to humanize: ").strip()
        
        if text.lower() in ['quit', 'exit', 'q']:
            print("πŸ‘‹ Goodbye!")
            break
            
        if not text:
            print("⚠️ Please enter some text.")
            continue
        
        # Get style preference
        print("\n🎨 Choose style:")
        print("1. Natural")
        print("2. Casual") 
        print("3. Conversational")
        
        style_choice = input("Enter choice (1-3) or press Enter for Natural: ").strip()
        style_map = {'1': 'natural', '2': 'casual', '3': 'conversational'}
        style = style_map.get(style_choice, 'natural')
        
        # Get intensity
        intensity_input = input("⚑ Enter intensity (0.1-1.0) or press Enter for 0.7: ").strip()
        try:
            intensity = float(intensity_input) if intensity_input else 0.7
            intensity = max(0.1, min(1.0, intensity))  # Clamp between 0.1 and 1.0
        except ValueError:
            intensity = 0.7
        
        print(f"\nπŸš€ Processing with {style} style, intensity {intensity}...")
        
        result = humanize_single_text(text, style, intensity)
        display_result(result)
        
        print("\n" + "-"*60 + "\n")

def run_examples():
    """Run example demonstrations"""
    print("\n🎯 Running Example Tests")
    print("=" * 50)
    
    examples = [
        {
            "text": "Furthermore, it is important to note that artificial intelligence systems demonstrate significant capabilities in natural language processing tasks. Subsequently, these systems can analyze and generate text with remarkable accuracy.",
            "style": "conversational",
            "intensity": 0.8,
            "description": "AI-formal text β†’ Conversational"
        },
        {
            "text": "The implementation of this comprehensive solution will facilitate the optimization of business processes and operational workflows. Moreover, it will demonstrate substantial improvements in efficiency metrics.",
            "style": "natural",
            "intensity": 0.6,
            "description": "Business text β†’ Natural"
        },
        {
            "text": "In conclusion, the systematic analysis reveals that the proposed methodology demonstrates significant potential for enhancing performance indicators.",
            "style": "casual",
            "intensity": 0.7,
            "description": "Academic text β†’ Casual"
        }
    ]
    
    for i, example in enumerate(examples, 1):
        print(f"\nπŸ”¬ Example {i}: {example['description']}")
        print("-" * 50)
        
        result = humanize_single_text(
            text=example['text'],
            style=example['style'],
            intensity=example['intensity']
        )
        
        display_result(result)
        
        # Small delay between examples
        time.sleep(1)

def test_batch_processing():
    """Test batch processing functionality"""
    print("\nπŸ”„ Testing Batch Processing")
    print("=" * 50)
    
    texts = [
        "Furthermore, the comprehensive analysis demonstrates significant improvements.",
        "Subsequently, the implementation will facilitate optimization of processes.",
        "Therefore, it is essential to utilize these methodologies effectively."
    ]
    
    print(f"πŸ“¦ Processing {len(texts)} texts in batch...")
    
    start_time = time.time()
    result = humanize_batch_texts(texts, style="casual", intensity=0.7)
    total_time = time.time() - start_time
    
    if result:
        print(f"\nβœ… Batch processing completed in {total_time:.1f}s")
        print(f"⚑ Total API time: {result['total_processing_time_ms']:.1f}ms")
        
        for i, text_result in enumerate(result['results'], 1):
            print(f"\nπŸ“ Text {i}:")
            print(f"   Original: {text_result['original_text'][:50]}...")
            print(f"   Humanized: {text_result['humanized_text'][:50]}...")
            print(f"   Similarity: {text_result['similarity_score']:.3f}")

def main():
    """Main function"""
    print("πŸ€–βž‘οΈπŸ‘€ AI Text Humanizer - API Client")
    print("=" * 50)
    
    # Test API connection
    if not test_api_connection():
        return
    
    while True:
        print("\n🎯 Choose an option:")
        print("1. Run example demonstrations")
        print("2. Test batch processing") 
        print("3. Interactive mode")
        print("4. Exit")
        
        choice = input("\nEnter your choice (1-4): ").strip()
        
        if choice == '1':
            run_examples()
        elif choice == '2':
            test_batch_processing()
        elif choice == '3':
            interactive_mode()
        elif choice == '4':
            print("\nπŸ‘‹ Thanks for using AI Text Humanizer!")
            break
        else:
            print("❌ Invalid choice. Please enter 1, 2, 3, or 4.")

if __name__ == "__main__":
    main()