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:
|
|
@@ -41,14 +41,11 @@ class HumanTouchApp:
|
|
| 41 |
return "## 🔴 Configuration Error\n\nThe `GROQ_API_KEY` is not set on the server. Please contact the Space administrator."
|
| 42 |
try:
|
| 43 |
logging.info(f"Calling Groq API with Style: {style_level}, Tone: {tone_level}")
|
| 44 |
-
|
| 45 |
messages = [
|
| 46 |
{"role": "system", "content": self.system_prompt_template},
|
| 47 |
{"role": "user", "content": f"Style: {style_level}, Tone: {tone_level}\n\n---\n\n{user_content}"}
|
| 48 |
]
|
| 49 |
-
|
| 50 |
temperature = 0.5 + (style_level / 200) + (tone_level / 400)
|
| 51 |
-
|
| 52 |
response = self.client.chat.completions.create(
|
| 53 |
model=self.model,
|
| 54 |
messages=messages,
|
|
@@ -60,17 +57,14 @@ class HumanTouchApp:
|
|
| 60 |
logging.error(f"Error during Groq API call: {e}")
|
| 61 |
return f"### ⚠️ An Error Occurred\n\nThere was an issue connecting to the AI. Please try again shortly. \n\n*Details: {str(e)}*"
|
| 62 |
|
| 63 |
-
# Method for the "Humanizer" Tab
|
| 64 |
def humanize_block_text(self, text_to_humanize: str, style_level: float, tone_level: float) -> str:
|
| 65 |
if not text_to_humanize.strip():
|
| 66 |
return "Please paste some AI-generated text to get started."
|
| 67 |
return self._call_groq_api(text_to_humanize, style_level, tone_level)
|
| 68 |
|
| 69 |
-
# Method for the "Co-Creative Canvas" Tab
|
| 70 |
def generate_co_creation(self, user_text: str, chat_history: List[List[str]], style_level: float, tone_level: float) -> Tuple[List[List[str]], str]:
|
| 71 |
if not user_text.strip():
|
| 72 |
return chat_history, ""
|
| 73 |
-
|
| 74 |
ai_response = self._call_groq_api(user_text, style_level, tone_level)
|
| 75 |
chat_history.append([user_text, ai_response])
|
| 76 |
return chat_history, ""
|
|
@@ -79,7 +73,7 @@ class HumanTouchApp:
|
|
| 79 |
def create_interface():
|
| 80 |
app = HumanTouchApp()
|
| 81 |
|
| 82 |
-
#
|
| 83 |
custom_css = """
|
| 84 |
/* --- Main Background and Font --- */
|
| 85 |
body, #main_container {
|
|
@@ -93,8 +87,7 @@ def create_interface():
|
|
| 93 |
|
| 94 |
/* --- Tab Container (Frosted Glass Look) --- */
|
| 95 |
.gradio-tabs {
|
| 96 |
-
background: rgba(255, 255, 255, 0.75);
|
| 97 |
-
border: 1px solid rgba(255, 255, 255, 0.18);
|
| 98 |
backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
|
| 99 |
border-radius: 20px !important; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.25);
|
| 100 |
padding: 1rem;
|
|
@@ -109,7 +102,7 @@ def create_interface():
|
|
| 109 |
/* --- Humanizer Tab Styles --- */
|
| 110 |
#humanizer_input, #humanizer_output {
|
| 111 |
border: 2px solid #E0E0E0; border-radius: 12px;
|
| 112 |
-
background: #fff; min-height: 45vh; color: #263238;
|
| 113 |
}
|
| 114 |
#humanize_btn {
|
| 115 |
background: linear-gradient(45deg, #F06292, #4FC3F7); color: white;
|
|
@@ -121,22 +114,26 @@ def create_interface():
|
|
| 121 |
/* --- Co-Creative Canvas Tab Styles --- */
|
| 122 |
#symbiotic_canvas { background: #fff; border-radius: 12px; height: 60vh !important; border: 2px solid #E0E0E0; }
|
| 123 |
|
| 124 |
-
/* === FIX FOR TEXT LEGIBILITY === */
|
| 125 |
-
#symbiotic_canvas .
|
| 126 |
-
|
| 127 |
-
|
| 128 |
border-radius: 18px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
}
|
| 130 |
#symbiotic_canvas .bot {
|
| 131 |
-
background-color: #
|
| 132 |
-
color: #
|
| 133 |
-
font-weight: 500 !important;
|
| 134 |
-
border: 1px solid #
|
| 135 |
-
|
| 136 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
| 137 |
-
animation: bloom 0.7s ease-out;
|
| 138 |
}
|
| 139 |
-
@keyframes bloom { 0% { opacity: 0; transform:
|
| 140 |
|
| 141 |
#chat_input textarea { border-radius: 9999px !important; border: 2px solid #E0E0E0; }
|
| 142 |
#compose_btn { background: linear-gradient(45deg, #4FC3F7, #F06292); border: none; }
|
|
@@ -158,6 +155,7 @@ def create_interface():
|
|
| 158 |
|
| 159 |
with gr.Tabs() as tabs:
|
| 160 |
with gr.Tab("Humanizer", id="humanizer_tab"):
|
|
|
|
| 161 |
with gr.Column(variant="panel"):
|
| 162 |
gr.Markdown("### Transform Existing AI Text")
|
| 163 |
with gr.Row():
|
|
@@ -170,6 +168,7 @@ def create_interface():
|
|
| 170 |
gr.Examples([["The system's analysis concluded optimal parameters were achieved."]], inputs=[input_text_humanizer], label="Try an Example")
|
| 171 |
|
| 172 |
with gr.Tab("Co-Creative Canvas", id="canvas_tab"):
|
|
|
|
| 173 |
with gr.Row(equal_height=False):
|
| 174 |
with gr.Column(scale=3):
|
| 175 |
chatbot = gr.Chatbot([], label="Symbiotic Canvas", elem_id="symbiotic_canvas", bubble_full_width=True, avatar_images=(None, "https://i.imgur.com/Q6Zz3Jz.png"))
|
|
@@ -191,7 +190,7 @@ def create_interface():
|
|
| 191 |
|
| 192 |
|
| 193 |
if __name__ == "__main__":
|
| 194 |
-
logging.info("Launching HumanTouch App with
|
| 195 |
try:
|
| 196 |
interface = create_interface()
|
| 197 |
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 ---
|
| 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:
|
|
|
|
| 41 |
return "## 🔴 Configuration Error\n\nThe `GROQ_API_KEY` is not set on the server. Please contact the Space administrator."
|
| 42 |
try:
|
| 43 |
logging.info(f"Calling Groq API with Style: {style_level}, Tone: {tone_level}")
|
|
|
|
| 44 |
messages = [
|
| 45 |
{"role": "system", "content": self.system_prompt_template},
|
| 46 |
{"role": "user", "content": f"Style: {style_level}, Tone: {tone_level}\n\n---\n\n{user_content}"}
|
| 47 |
]
|
|
|
|
| 48 |
temperature = 0.5 + (style_level / 200) + (tone_level / 400)
|
|
|
|
| 49 |
response = self.client.chat.completions.create(
|
| 50 |
model=self.model,
|
| 51 |
messages=messages,
|
|
|
|
| 57 |
logging.error(f"Error during Groq API call: {e}")
|
| 58 |
return f"### ⚠️ An Error Occurred\n\nThere was an issue connecting to the AI. Please try again shortly. \n\n*Details: {str(e)}*"
|
| 59 |
|
|
|
|
| 60 |
def humanize_block_text(self, text_to_humanize: str, style_level: float, tone_level: float) -> str:
|
| 61 |
if not text_to_humanize.strip():
|
| 62 |
return "Please paste some AI-generated text to get started."
|
| 63 |
return self._call_groq_api(text_to_humanize, style_level, tone_level)
|
| 64 |
|
|
|
|
| 65 |
def generate_co_creation(self, user_text: str, chat_history: List[List[str]], style_level: float, tone_level: float) -> Tuple[List[List[str]], str]:
|
| 66 |
if not user_text.strip():
|
| 67 |
return chat_history, ""
|
|
|
|
| 68 |
ai_response = self._call_groq_api(user_text, style_level, tone_level)
|
| 69 |
chat_history.append([user_text, ai_response])
|
| 70 |
return chat_history, ""
|
|
|
|
| 73 |
def create_interface():
|
| 74 |
app = HumanTouchApp()
|
| 75 |
|
| 76 |
+
# CSS with aggressive legibility fixes
|
| 77 |
custom_css = """
|
| 78 |
/* --- Main Background and Font --- */
|
| 79 |
body, #main_container {
|
|
|
|
| 87 |
|
| 88 |
/* --- Tab Container (Frosted Glass Look) --- */
|
| 89 |
.gradio-tabs {
|
| 90 |
+
background: rgba(255, 255, 255, 0.75); border: 1px solid rgba(255, 255, 255, 0.18);
|
|
|
|
| 91 |
backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
|
| 92 |
border-radius: 20px !important; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.25);
|
| 93 |
padding: 1rem;
|
|
|
|
| 102 |
/* --- Humanizer Tab Styles --- */
|
| 103 |
#humanizer_input, #humanizer_output {
|
| 104 |
border: 2px solid #E0E0E0; border-radius: 12px;
|
| 105 |
+
background: #fff; min-height: 45vh; color: #263238; font-size: 16px;
|
| 106 |
}
|
| 107 |
#humanize_btn {
|
| 108 |
background: linear-gradient(45deg, #F06292, #4FC3F7); color: white;
|
|
|
|
| 114 |
/* --- Co-Creative Canvas Tab Styles --- */
|
| 115 |
#symbiotic_canvas { background: #fff; border-radius: 12px; height: 60vh !important; border: 2px solid #E0E0E0; }
|
| 116 |
|
| 117 |
+
/* === FIX 2.0 FOR TEXT LEGIBILITY (AGGRESSIVE) === */
|
| 118 |
+
#symbiotic_canvas .message-wrap { padding: 4px !important; }
|
| 119 |
+
#symbiotic_canvas .user, #symbiotic_canvas .bot {
|
| 120 |
+
padding: 12px 16px !important;
|
| 121 |
border-radius: 18px !important;
|
| 122 |
+
font-size: 16px !important;
|
| 123 |
+
line-height: 1.5 !important;
|
| 124 |
+
}
|
| 125 |
+
#symbiotic_canvas .user {
|
| 126 |
+
background-color: #F3F4F6 !important; /* Neutral light grey for user */
|
| 127 |
+
color: #111827 !important; /* Dark charcoal text for user */
|
| 128 |
}
|
| 129 |
#symbiotic_canvas .bot {
|
| 130 |
+
background-color: #EFF6FF !important; /* Very light, clean blue background */
|
| 131 |
+
color: #1E3A8A !important; /* VERY DARK blue text for maximum contrast */
|
| 132 |
+
font-weight: 500 !important;
|
| 133 |
+
border: 1px solid #DBEAFE !important;
|
| 134 |
+
animation: bloom 0.5s ease-out;
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
+
@keyframes bloom { 0% { opacity: 0; transform: scale(0.95); } 100% { opacity: 1; transform: scale(1); } }
|
| 137 |
|
| 138 |
#chat_input textarea { border-radius: 9999px !important; border: 2px solid #E0E0E0; }
|
| 139 |
#compose_btn { background: linear-gradient(45deg, #4FC3F7, #F06292); border: none; }
|
|
|
|
| 155 |
|
| 156 |
with gr.Tabs() as tabs:
|
| 157 |
with gr.Tab("Humanizer", id="humanizer_tab"):
|
| 158 |
+
# ... Humanizer tab layout ...
|
| 159 |
with gr.Column(variant="panel"):
|
| 160 |
gr.Markdown("### Transform Existing AI Text")
|
| 161 |
with gr.Row():
|
|
|
|
| 168 |
gr.Examples([["The system's analysis concluded optimal parameters were achieved."]], inputs=[input_text_humanizer], label="Try an Example")
|
| 169 |
|
| 170 |
with gr.Tab("Co-Creative Canvas", id="canvas_tab"):
|
| 171 |
+
# ... Canvas tab layout ...
|
| 172 |
with gr.Row(equal_height=False):
|
| 173 |
with gr.Column(scale=3):
|
| 174 |
chatbot = gr.Chatbot([], label="Symbiotic Canvas", elem_id="symbiotic_canvas", bubble_full_width=True, avatar_images=(None, "https://i.imgur.com/Q6Zz3Jz.png"))
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
if __name__ == "__main__":
|
| 193 |
+
logging.info("Launching HumanTouch App with Definitive Legibility Fix...")
|
| 194 |
try:
|
| 195 |
interface = create_interface()
|
| 196 |
interface.launch(debug=True)
|