Spaces:
Running
Running
File size: 8,503 Bytes
6ef9704 f43f7c7 e683cda 6ef9704 e683cda 5c9a55b e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 7dec80a 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 7dec80a 5c9a55b 7dec80a e683cda 7dec80a e683cda 7dec80a e683cda 5b7b927 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 7dec80a e683cda 7dec80a 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 5c9a55b 6ef9704 e683cda 5c9a55b e683cda 6ef9704 e683cda a9b4a28 6ef9704 e683cda 6ef9704 e683cda a9b4a28 6ef9704 7dec80a e683cda 6ef9704 a9b4a28 e683cda a9b4a28 e683cda a9b4a28 e683cda 7dec80a 6ef9704 e683cda 7dec80a e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 e683cda 6ef9704 |
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 |
import gradio as gr
import time
import os
# Import our humanizer
from text_humanizer import AITextHumanizer
# Initialize the humanizer
print("π Loading AI Text Humanizer for Hugging Face Spaces...")
try:
humanizer = AITextHumanizer()
print("β
Humanizer loaded successfully!")
except Exception as e:
print(f"β Error loading humanizer: {e}")
humanizer = None
def humanize_text_hf(text, style, intensity):
"""
Hugging Face Spaces interface function for text humanization
"""
if not text.strip():
return "β οΈ Please enter some text to humanize.", "", 0.0, "No changes made", 0.0
if humanizer is None:
return "β Error: Humanizer not loaded properly.", "", 0.0, "System error", 0.0
try:
start_time = time.time()
# Humanize the text
result = humanizer.humanize_text(
text=text,
style=style.lower(),
intensity=intensity
)
processing_time = (time.time() - start_time) * 1000
changes_text = ", ".join(result["changes_made"]) if result["changes_made"] else "No significant changes made"
return (
result["humanized_text"],
f"**π Processing Results:**\n- **Similarity Score:** {result['similarity_score']:.3f}\n- **Processing Time:** {processing_time:.1f}ms\n- **Style:** {result['style'].title()}\n- **Intensity:** {result['intensity']}\n\n**π Changes Made:** {changes_text}",
result["similarity_score"],
changes_text,
processing_time
)
except Exception as e:
return f"β Error processing text: {str(e)}", "", 0.0, "Processing error", 0.0
# Create the Hugging Face Spaces interface
with gr.Blocks(
title="π€β‘οΈπ€ AI Text Humanizer",
theme=gr.themes.Soft(),
css="""
.main-header {
text-align: center;
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
}
.stats-box {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
border-left: 4px solid #667eea;
}
"""
) as iface:
gr.HTML("""
<div class="main-header">
<h1>π€β‘οΈπ€ AI Text Humanizer</h1>
<p>Transform AI-generated text to sound more natural and human-like</p>
<p><em>Powered by advanced NLP techniques and transformers</em></p>
</div>
""")
with gr.Tab("π― Humanize Text"):
with gr.Row():
with gr.Column(scale=1):
gr.HTML("<h3>π Input</h3>")
input_text = gr.Textbox(
label="Text to Humanize",
placeholder="Paste your AI-generated text here...\n\nExample: Furthermore, it is important to note that artificial intelligence systems demonstrate significant capabilities...",
lines=10,
max_lines=20
)
with gr.Row():
style_dropdown = gr.Dropdown(
choices=["Natural", "Casual", "Conversational"],
value="Natural",
label="π¨ Humanization Style"
)
intensity_slider = gr.Slider(
minimum=0.1,
maximum=1.0,
value=0.7,
step=0.1,
label="β‘ Intensity Level"
)
humanize_btn = gr.Button(
"π Humanize Text",
variant="primary",
size="lg"
)
with gr.Column(scale=1):
gr.HTML("<h3>β¨ Output</h3>")
output_text = gr.Textbox(
label="Humanized Text",
lines=10,
max_lines=20,
show_copy_button=True
)
stats_output = gr.Markdown(
label="π Processing Statistics",
value="Results will appear here after processing..."
)
with gr.Tab("π Examples & Guide"):
gr.HTML("<h3>π‘ Try These Examples</h3>")
# Examples
examples = gr.Examples(
examples=[
[
"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. Nevertheless, it is crucial to understand that human oversight remains essential for optimal performance.",
"Conversational",
0.8
],
[
"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 while maintaining quality standards.",
"Natural",
0.6
],
[
"In conclusion, the systematic analysis reveals that the proposed methodology demonstrates significant potential for enhancing performance indicators. Additionally, the structured approach ensures optimal resource utilization.",
"Casual",
0.7
]
],
inputs=[input_text, style_dropdown, intensity_slider],
outputs=[output_text, stats_output],
fn=humanize_text_hf,
cache_examples=False
)
gr.HTML("""
<div style="margin-top: 30px;">
<h3>π― How It Works</h3>
<div class="stats-box">
<h4>π§ Transformation Techniques:</h4>
<ul>
<li><strong>Smart Word Replacement:</strong> formal words β casual alternatives</li>
<li><strong>Contraction Addition:</strong> "do not" β "don't", "it is" β "it's"</li>
<li><strong>AI Transition Removal:</strong> removes robotic transition phrases</li>
<li><strong>Sentence Restructuring:</strong> varies length and structure</li>
<li><strong>Natural Imperfections:</strong> adds human-like variations</li>
<li><strong>Context-Aware Paraphrasing:</strong> maintains meaning while improving flow</li>
</ul>
</div>
<div class="stats-box" style="margin-top: 15px;">
<h4>π¨ Style Guide:</h4>
<ul>
<li><strong>Natural (0.5-0.7):</strong> Professional content with human touch</li>
<li><strong>Casual (0.6-0.8):</strong> Blog posts, articles, informal content</li>
<li><strong>Conversational (0.7-1.0):</strong> Social media, very informal text</li>
</ul>
</div>
<div class="stats-box" style="margin-top: 15px;">
<h4>β‘ Performance:</h4>
<ul>
<li><strong>Similarity Preservation:</strong> Maintains 85-95% semantic similarity</li>
<li><strong>Processing Speed:</strong> ~500ms for typical paragraphs</li>
<li><strong>Quality:</strong> Advanced NLP models ensure high-quality output</li>
</ul>
</div>
</div>
""")
# Event handlers
humanize_btn.click(
fn=humanize_text_hf,
inputs=[input_text, style_dropdown, intensity_slider],
outputs=[output_text, stats_output]
)
# Launch for Hugging Face Spaces
if __name__ == "__main__":
print("π Launching AI Text Humanizer on Hugging Face Spaces...")
iface.launch(
share=False, # HF Spaces handles sharing
server_name="0.0.0.0",
server_port=7860,
show_error=True
) |