Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,11 +7,11 @@ from typing import List, Tuple
|
|
| 7 |
# --- Basic Configuration ---
|
| 8 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
|
| 9 |
|
| 10 |
-
# --- The Core Application Logic (
|
| 11 |
class HumanTouchApp:
|
| 12 |
def __init__(self):
|
| 13 |
self.client = self._initialize_groq_client()
|
| 14 |
-
self.model = "llama-3.
|
| 15 |
self.system_prompt_template = self._load_system_prompt()
|
| 16 |
|
| 17 |
def _initialize_groq_client(self) -> Groq:
|
|
@@ -23,7 +23,7 @@ class HumanTouchApp:
|
|
| 23 |
return Groq(api_key=api_key)
|
| 24 |
|
| 25 |
def _load_system_prompt(self) -> str:
|
| 26 |
-
# This one prompt
|
| 27 |
return """
|
| 28 |
You are HumanTouch, an AI specializing in transforming text into emotionally resonant communication.
|
| 29 |
Your output style is guided by two scores: Style (0=Logical, 100=Poetic) and Tone (0=Formal, 100=Passionate).
|
|
@@ -100,43 +100,79 @@ class HumanTouchApp:
|
|
| 100 |
def create_interface():
|
| 101 |
app = HumanTouchApp()
|
| 102 |
|
|
|
|
| 103 |
custom_css = """
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
#header h1 { font-size: 2.5rem; font-weight: 600; }
|
| 107 |
-
#header p { font-size: 1.1rem; color: #
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
/* --- Humanizer Tab Styles --- */
|
| 113 |
-
#humanizer_input, #humanizer_output {
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
#
|
| 119 |
-
#
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
"""
|
| 124 |
|
| 125 |
-
with gr.Blocks(css=custom_css,
|
| 126 |
with gr.Column(elem_id="main_container"):
|
| 127 |
with gr.Row(elem_id="header"):
|
| 128 |
-
gr.Markdown("<h1>
|
| 129 |
|
| 130 |
with gr.Tabs() as tabs:
|
| 131 |
# --- TAB 1: The Humanizer ---
|
| 132 |
with gr.Tab("Humanizer", id="humanizer_tab"):
|
| 133 |
-
with gr.Column():
|
| 134 |
-
gr.Markdown("###
|
| 135 |
with gr.Row():
|
| 136 |
-
with gr.Column(scale=
|
| 137 |
-
input_text_humanizer = gr.Textbox(label="Paste AI Text Here", lines=
|
| 138 |
-
with gr.Column(scale=
|
| 139 |
-
output_text_humanizer = gr.Textbox(label="Humanized Result", lines=
|
| 140 |
with gr.Row():
|
| 141 |
with gr.Column(scale=1):
|
| 142 |
style_slider_h = gr.Slider(0, 100, 50, label="Style (Logical <-> Poetic)")
|
|
@@ -146,7 +182,7 @@ def create_interface():
|
|
| 146 |
gr.Examples(
|
| 147 |
[["The system's analysis concluded that the optimal parameters were achieved through iterative processing."],
|
| 148 |
["Our team will action the deliverables post-haste to synergize our market position."]],
|
| 149 |
-
inputs=[input_text_humanizer], label="Try
|
| 150 |
)
|
| 151 |
|
| 152 |
# --- TAB 2: The Co-Creative Canvas ---
|
|
@@ -154,10 +190,10 @@ def create_interface():
|
|
| 154 |
with gr.Row(equal_height=False):
|
| 155 |
with gr.Column(scale=3):
|
| 156 |
chatbot = gr.Chatbot([], label="Symbiotic Canvas", elem_id="symbiotic_canvas", bubble_full_width=True, avatar_images=(None, "https://i.imgur.com/Q6Zz3Jz.png"))
|
| 157 |
-
with gr.Row(
|
| 158 |
-
chat_input = gr.Textbox(placeholder="Start a thought
|
| 159 |
-
|
| 160 |
-
with gr.Column(scale=1,
|
| 161 |
gr.Markdown("### Resonance Controls")
|
| 162 |
style_slider_c = gr.Slider(0, 100, 50, label="Style", info="Logical <-> Poetic")
|
| 163 |
tone_slider_c = gr.Slider(0, 100, 50, label="Tone", info="Formal <-> Passionate")
|
|
@@ -167,26 +203,15 @@ def create_interface():
|
|
| 167 |
)
|
| 168 |
|
| 169 |
# Event Handling Logic
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
[input_text_humanizer, style_slider_h, tone_slider_h],
|
| 174 |
-
[output_text_humanizer]
|
| 175 |
-
)
|
| 176 |
-
|
| 177 |
-
# Canvas Tab
|
| 178 |
-
chat_input.submit(
|
| 179 |
-
app.generate_co_creation,
|
| 180 |
-
[chat_input, chatbot, style_slider_c, tone_slider_c],
|
| 181 |
-
[chatbot, chat_input]
|
| 182 |
-
)
|
| 183 |
-
clear_btn.click(lambda: ([], ""), [], [chatbot, chat_input])
|
| 184 |
|
| 185 |
return interface
|
| 186 |
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
logging.info("Launching HumanTouch App with Blended UI...")
|
| 190 |
try:
|
| 191 |
interface = create_interface()
|
| 192 |
interface.launch(debug=True)
|
|
|
|
| 7 |
# --- Basic Configuration ---
|
| 8 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
|
| 9 |
|
| 10 |
+
# --- The Core Application Logic (Serves both modes) ---
|
| 11 |
class HumanTouchApp:
|
| 12 |
def __init__(self):
|
| 13 |
self.client = self._initialize_groq_client()
|
| 14 |
+
self.model = "llama-3.1-70b-versatile"
|
| 15 |
self.system_prompt_template = self._load_system_prompt()
|
| 16 |
|
| 17 |
def _initialize_groq_client(self) -> Groq:
|
|
|
|
| 23 |
return Groq(api_key=api_key)
|
| 24 |
|
| 25 |
def _load_system_prompt(self) -> str:
|
| 26 |
+
# This one prompt powers both modes, using context to differentiate tasks.
|
| 27 |
return """
|
| 28 |
You are HumanTouch, an AI specializing in transforming text into emotionally resonant communication.
|
| 29 |
Your output style is guided by two scores: Style (0=Logical, 100=Poetic) and Tone (0=Formal, 100=Passionate).
|
|
|
|
| 100 |
def create_interface():
|
| 101 |
app = HumanTouchApp()
|
| 102 |
|
| 103 |
+
# This CSS combines the light, colorful aesthetic with the components of the tabbed interface.
|
| 104 |
custom_css = """
|
| 105 |
+
/* --- Main Background and Font --- */
|
| 106 |
+
body, #main_container {
|
| 107 |
+
background: linear-gradient(135deg, #f0f9ff, #fff0f5); /* Softer blue-to-pink gradient */
|
| 108 |
+
font-family: 'Arial', sans-serif;
|
| 109 |
+
}
|
| 110 |
+
/* --- Header Styling --- */
|
| 111 |
+
#header { text-align: center; margin: 2rem auto; color: #2D3748; }
|
| 112 |
#header h1 { font-size: 2.5rem; font-weight: 600; }
|
| 113 |
+
#header p { font-size: 1.1rem; color: #4A5568; margin-bottom: 2rem; }
|
| 114 |
+
|
| 115 |
+
/* --- Tab Container (Frosted Glass Look) --- */
|
| 116 |
+
.gradio-tabs {
|
| 117 |
+
background: rgba(255, 255, 255, 0.8);
|
| 118 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
| 119 |
+
backdrop-filter: blur(10px);
|
| 120 |
+
border-radius: 20px !important;
|
| 121 |
+
box-shadow: 0 8px 32px 0 rgba(100, 100, 135, 0.2);
|
| 122 |
+
padding: 1rem;
|
| 123 |
+
}
|
| 124 |
+
.tab-buttons button {
|
| 125 |
+
background-color: transparent !important; color: #4A5568 !important;
|
| 126 |
+
border: none !important; border-bottom: 2px solid transparent !important;
|
| 127 |
+
border-radius: 0 !important; font-size: 1.1rem;
|
| 128 |
+
}
|
| 129 |
+
.tab-buttons button.selected {
|
| 130 |
+
color: #3182CE !important;
|
| 131 |
+
border-bottom-color: #3182CE !important;
|
| 132 |
+
}
|
| 133 |
|
| 134 |
/* --- Humanizer Tab Styles --- */
|
| 135 |
+
#humanizer_input, #humanizer_output {
|
| 136 |
+
border: 2px solid #E2E8F0; border-radius: 12px; padding: 1rem;
|
| 137 |
+
background: white; transition: border-color 0.3s ease; min-height: 45vh;
|
| 138 |
+
color: #2D3748;
|
| 139 |
+
}
|
| 140 |
+
#humanizer_input:focus-within, #humanizer_output:focus-within { border-color: #3182CE; }
|
| 141 |
+
#humanize_btn {
|
| 142 |
+
background: linear-gradient(45deg, #ED64A6, #4299E1);
|
| 143 |
+
padding: 15px 24px; border-radius: 9999px; font-size: 1.2rem;
|
| 144 |
+
transition: all 0.3s ease;
|
| 145 |
+
}
|
| 146 |
+
#humanize_btn:hover { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); transform: translateY(-2px); }
|
| 147 |
+
|
| 148 |
+
/* --- Co-Creative Canvas Tab Styles --- */
|
| 149 |
+
#symbiotic_canvas {
|
| 150 |
+
background: white; border-radius: 12px; height: 60vh !important;
|
| 151 |
+
border: 2px solid #E2E8F0;
|
| 152 |
+
}
|
| 153 |
+
#symbiotic_canvas .user { background-color: #F7FAFC !important; color: #2D3748; border-radius: 15px; }
|
| 154 |
+
#symbiotic_canvas .bot { background-color: #E6FFFA !important; color: #2C7A7B; border-radius: 15px; animation: bloom 0.7s ease-in-out; }
|
| 155 |
+
@keyframes bloom { 0% { opacity: 0; transform: translateY(10px); } 100% { opacity: 1; transform: translateY(0); } }
|
| 156 |
+
|
| 157 |
+
#chat_input textarea { border-radius: 9999px !important; border: 2px solid #E2E8F0; }
|
| 158 |
+
#compose_btn { background: #4299E1; }
|
| 159 |
"""
|
| 160 |
|
| 161 |
+
with gr.Blocks(css=custom_css, title="HumanTouch") as interface:
|
| 162 |
with gr.Column(elem_id="main_container"):
|
| 163 |
with gr.Row(elem_id="header"):
|
| 164 |
+
gr.Markdown("<h1>🧙♂️ HumanTouch</h1><p>Breathe life into AI text or co-create with a dynamic AI partner.</p>")
|
| 165 |
|
| 166 |
with gr.Tabs() as tabs:
|
| 167 |
# --- TAB 1: The Humanizer ---
|
| 168 |
with gr.Tab("Humanizer", id="humanizer_tab"):
|
| 169 |
+
with gr.Column(variant="panel"):
|
| 170 |
+
gr.Markdown("### Transform Existing AI Text")
|
| 171 |
with gr.Row():
|
| 172 |
+
with gr.Column(scale=1):
|
| 173 |
+
input_text_humanizer = gr.Textbox(label="Paste AI Text Here", lines=15, elem_id="humanizer_input")
|
| 174 |
+
with gr.Column(scale=1):
|
| 175 |
+
output_text_humanizer = gr.Textbox(label="Humanized Result", lines=15, interactive=False, elem_id="humanizer_output")
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column(scale=1):
|
| 178 |
style_slider_h = gr.Slider(0, 100, 50, label="Style (Logical <-> Poetic)")
|
|
|
|
| 182 |
gr.Examples(
|
| 183 |
[["The system's analysis concluded that the optimal parameters were achieved through iterative processing."],
|
| 184 |
["Our team will action the deliverables post-haste to synergize our market position."]],
|
| 185 |
+
inputs=[input_text_humanizer], label="Try a Humanizer Example"
|
| 186 |
)
|
| 187 |
|
| 188 |
# --- TAB 2: The Co-Creative Canvas ---
|
|
|
|
| 190 |
with gr.Row(equal_height=False):
|
| 191 |
with gr.Column(scale=3):
|
| 192 |
chatbot = gr.Chatbot([], label="Symbiotic Canvas", elem_id="symbiotic_canvas", bubble_full_width=True, avatar_images=(None, "https://i.imgur.com/Q6Zz3Jz.png"))
|
| 193 |
+
with gr.Row():
|
| 194 |
+
chat_input = gr.Textbox(placeholder="Start a thought...", show_label=False, container=False, scale=4)
|
| 195 |
+
compose_btn = gr.Button("Compose ✨", variant="primary", scale=1, elem_id="compose_btn")
|
| 196 |
+
with gr.Column(scale=1, variant="panel"):
|
| 197 |
gr.Markdown("### Resonance Controls")
|
| 198 |
style_slider_c = gr.Slider(0, 100, 50, label="Style", info="Logical <-> Poetic")
|
| 199 |
tone_slider_c = gr.Slider(0, 100, 50, label="Tone", info="Formal <-> Passionate")
|
|
|
|
| 203 |
)
|
| 204 |
|
| 205 |
# Event Handling Logic
|
| 206 |
+
humanize_button.click(app.humanize_block_text, [input_text_humanizer, style_slider_h, tone_slider_h], [output_text_humanizer])
|
| 207 |
+
compose_btn.click(app.generate_co_creation, [chat_input, chatbot, style_slider_c, tone_slider_c], [chatbot, chat_input])
|
| 208 |
+
chat_input.submit(app.generate_co_creation, [chat_input, chatbot, style_slider_c, tone_slider_c], [chatbot, chat_input])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
return interface
|
| 211 |
|
| 212 |
|
| 213 |
if __name__ == "__main__":
|
| 214 |
+
logging.info("Launching HumanTouch App with Blended UI and Light Theme...")
|
| 215 |
try:
|
| 216 |
interface = create_interface()
|
| 217 |
interface.launch(debug=True)
|