File size: 14,176 Bytes
3593f9b 30370bb 3593f9b 4c73b94 30370bb 4c73b94 30370bb 4c73b94 30370bb 4c73b94 30370bb 4c73b94 30370bb 4c73b94 30370bb 4c73b94 |
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
import streamlit as st
from PIL import Image, ImageDraw, ImageFont
import io
import textwrap
import urllib.parse
# Demo mode for deployment environments without heavy ML dependencies
DEMO_MODE = True
def transform_text(text, mode="To Corporate", domain="general", seniority="mid"):
"""Demo transformation without ML model"""
if mode == "To Corporate":
# Enhanced corporate transformations
corporate_map = {
"let's meet": "I would appreciate the opportunity to sync up",
"meet tomorrow": "sync up tomorrow to align on our objectives",
"i need help": "I require assistance with these deliverables",
"need help with": "require support to optimize",
"good job": "Excellent execution on this initiative",
"great work": "Outstanding performance on the deliverables",
"what's up": "I hope this message finds you well",
"how's it going": "I wanted to touch base on current progress",
"thanks": "I appreciate your collaboration",
"thank you": "I'm grateful for your partnership",
"ok": "Understood, I'll proceed accordingly",
"sure": "Certainly, I'd be happy to assist",
"got it": "I acknowledge and will action accordingly",
"my bad": "I apologize for the oversight",
"sorry": "I regret any inconvenience",
"asap": "at your earliest convenience",
"right away": "with expedited priority",
"fyi": "for your awareness",
"by the way": "additionally, I wanted to mention",
"btw": "furthermore",
"let's start": "let's operationalize this initiative",
"let's begin": "let's commence the deliverables",
"fix this": "address these challenges",
"problem": "opportunity for improvement",
"issue": "consideration that requires attention",
"busy": "operating at full bandwidth",
"swamped": "currently resource-constrained"
}
result = text.lower()
for casual, corporate in corporate_map.items():
if casual in result:
result = result.replace(casual, corporate)
# Add domain-specific enhancements
if domain == "tech":
if "project" in result:
result = result.replace("project", "sprint initiative")
result += " leveraging our agile methodology"
elif domain == "finance":
if "money" in result:
result = result.replace("money", "capital allocation")
result += " ensuring regulatory compliance"
elif domain == "consulting":
if "idea" in result:
result = result.replace("idea", "strategic recommendation")
result += " aligned with best practices"
elif domain == "healthcare":
result += " maintaining patient-centered focus"
# Seniority-based adjustments
if seniority == "executive":
result = "From a strategic perspective, " + result
elif seniority == "senior":
result = "Based on my experience, " + result
return result.capitalize()
else:
# Enhanced reverse transformation
plain_map = {
"leverage": "use",
"synergize": "work together",
"operationalize": "start",
"deliverables": "work",
"action items": "tasks",
"circle back": "talk later",
"touch base": "meet",
"deep dive": "look closely",
"bandwidth": "time",
"stakeholder": "person involved",
"paradigm shift": "big change",
"low-hanging fruit": "easy wins",
"move the needle": "make a difference",
"game changer": "big improvement",
"best practices": "good ways",
"ecosystem": "environment",
"scalable": "can grow",
"robust": "strong",
"streamline": "simplify",
"optimize": "improve",
"facilitate": "help",
"utilize": "use",
"implement": "do",
"collaborate": "work together",
"ideate": "think of ideas",
"incentivize": "encourage"
}
result = text.lower()
for corporate, plain in plain_map.items():
result = result.replace(corporate, plain)
return result.capitalize()
def create_shareable_card(input_text, output_text, mode, domain, seniority):
"""Create a shareable image card with the transformation"""
# Card dimensions
width, height = 800, 600
# Colors
bg_color = "#f8f9fa"
primary_color = "#2c3e50"
secondary_color = "#3498db"
text_color = "#2c3e50"
# Create image
img = Image.new('RGB', (width, height), bg_color)
draw = ImageDraw.Draw(img)
try:
# Try to load a nicer font
title_font = ImageFont.truetype("arial.ttf", 28)
subtitle_font = ImageFont.truetype("arial.ttf", 18)
text_font = ImageFont.truetype("arial.ttf", 16)
small_font = ImageFont.truetype("arial.ttf", 14)
except:
# Fallback to default font
title_font = ImageFont.load_default()
subtitle_font = ImageFont.load_default()
text_font = ImageFont.load_default()
small_font = ImageFont.load_default()
# Title
title = "π’ Corporate Synergy Bot"
title_bbox = draw.textbbox((0, 0), title, font=title_font)
title_width = title_bbox[2] - title_bbox[0]
draw.text(((width - title_width) // 2, 30), title, fill=primary_color, font=title_font)
# Mode indicator
mode_text = f"{mode} β’ {domain.title()} β’ {seniority.title()}"
mode_bbox = draw.textbbox((0, 0), mode_text, font=subtitle_font)
mode_width = mode_bbox[2] - mode_bbox[0]
draw.text(((width - mode_width) // 2, 80), mode_text, fill=secondary_color, font=subtitle_font)
# Input section
draw.text((50, 140), "INPUT:", fill=primary_color, font=subtitle_font)
# Wrap input text
input_lines = textwrap.wrap(input_text, width=70)
y_pos = 170
for line in input_lines[:4]: # Max 4 lines
draw.text((50, y_pos), line, fill=text_color, font=text_font)
y_pos += 25
# Arrow
arrow = "β¬οΈ"
arrow_bbox = draw.textbbox((0, 0), arrow, font=title_font)
arrow_width = arrow_bbox[2] - arrow_bbox[0]
draw.text(((width - arrow_width) // 2, y_pos + 20), arrow, fill=secondary_color, font=title_font)
# Output section
y_pos += 80
draw.text((50, y_pos), "OUTPUT:", fill=primary_color, font=subtitle_font)
# Wrap output text
output_lines = textwrap.wrap(output_text, width=70)
y_pos += 30
for line in output_lines[:4]: # Max 4 lines
draw.text((50, y_pos), line, fill=text_color, font=text_font)
y_pos += 25
# Footer
footer_text = "Generated with Corporate Synergy Bot 7B (Demo)"
footer_bbox = draw.textbbox((0, 0), footer_text, font=small_font)
footer_width = footer_bbox[2] - footer_bbox[0]
draw.text(((width - footer_width) // 2, height - 40), footer_text, fill=secondary_color, font=small_font)
return img
def generate_linkedin_post_text(input_text, output_text, mode, domain):
"""Generate LinkedIn post text"""
if mode == "To Corporate":
post = f"""π’ Transform your communication with AI!
From casual: "{input_text}"
To professional: "{output_text}"
#{domain}Career #ProfessionalCommunication #CorporateSpeak #AI #WorkplaceCommunication #ProfessionalDevelopment
Try it yourself with Corporate Synergy Bot 7B! π"""
else:
post = f"""π¬ Decode corporate jargon with AI!
From corporate: "{input_text}"
To plain English: "{output_text}"
#ClearCommunication #CorporateJargon #WorkplaceCommunication #AI #ProfessionalDevelopment #PlainEnglish
Cut through the corporate speak with Corporate Synergy Bot 7B! β¨"""
return post
# Streamlit interface
st.set_page_config(
page_title="Corporate Synergy Bot 7B",
page_icon="π’",
layout="wide"
)
st.title("π’ Corporate Synergy Bot 7B")
if DEMO_MODE:
st.warning("β οΈ Demo Mode: Using rule-based transformations. Full AI model requires more resources.")
st.markdown("""
Transform casual language into professional corporate communication or decode corporate jargon back to plain English.
Powered by fine-tuned Mistral-7B with LoRA.
""")
col1, col2 = st.columns(2)
with col1:
st.subheader("Input")
input_text = st.text_area(
"Input Text",
placeholder="Enter text to transform...",
height=100,
key="input_text"
)
mode = st.radio(
"Transformation Mode",
["To Corporate", "To Plain English"],
index=0,
key="mode"
)
col1a, col1b = st.columns(2)
with col1a:
domain = st.selectbox(
"Domain (for corporate mode)",
["general", "tech", "finance", "consulting", "healthcare", "retail"],
index=0,
key="domain"
)
with col1b:
seniority = st.selectbox(
"Seniority Level",
["junior", "mid", "senior", "executive"],
index=1,
key="seniority"
)
transform_btn = st.button("Transform", type="primary", use_container_width=True)
with col2:
st.subheader("Output")
if transform_btn and input_text:
with st.spinner("Transforming..."):
output_text = transform_text(input_text, mode, domain, seniority)
st.text_area(
"Transformed Text",
value=output_text,
height=100,
key="output_text"
)
# Store the output for card generation
st.session_state.last_output = output_text
st.session_state.last_input = input_text
st.session_state.last_mode = mode
st.session_state.last_domain = domain
st.session_state.last_seniority = seniority
elif "last_output" in st.session_state:
st.text_area(
"Transformed Text",
value=st.session_state.last_output,
height=100,
key="output_display"
)
# Social sharing section
if "last_output" in st.session_state and "last_input" in st.session_state:
st.subheader("π± Share Your Transformation")
col_share1, col_share2 = st.columns(2)
with col_share1:
if st.button("π¨ Generate Shareable Card", use_container_width=True):
with st.spinner("Creating your card..."):
card_img = create_shareable_card(
st.session_state.last_input,
st.session_state.last_output,
st.session_state.last_mode,
st.session_state.last_domain,
st.session_state.last_seniority
)
# Convert to bytes for download
img_buffer = io.BytesIO()
card_img.save(img_buffer, format='PNG')
img_buffer.seek(0)
# Display the card
st.image(card_img, caption="Your shareable card", use_column_width=True)
# Download button
st.download_button(
label="πΎ Download Card",
data=img_buffer.getvalue(),
file_name="corporate_synergy_transformation.png",
mime="image/png",
use_container_width=True
)
with col_share2:
if st.button("π Generate LinkedIn Post", use_container_width=True):
linkedin_text = generate_linkedin_post_text(
st.session_state.last_input,
st.session_state.last_output,
st.session_state.last_mode,
st.session_state.last_domain
)
st.text_area(
"LinkedIn Post Text",
value=linkedin_text,
height=200,
key="linkedin_post"
)
# LinkedIn share button
linkedin_url = f"https://www.linkedin.com/sharing/share-offsite/?url={urllib.parse.quote('https://huggingface.co/spaces/phxdev/corporate-synergy-bot')}&summary={urllib.parse.quote(linkedin_text[:200])}"
st.markdown(f"""
<a href="{linkedin_url}" target="_blank">
<button style="
background-color: #0077B5;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
font-size: 16px;
text-decoration: none;
">
π Share on LinkedIn
</button>
</a>
""", unsafe_allow_html=True)
# Examples section
st.subheader("Examples")
examples = [
["let's meet tomorrow", "To Corporate", "general", "mid"],
["I need help with this project", "To Corporate", "tech", "senior"],
["good job on the presentation", "To Corporate", "consulting", "executive"],
["We need to leverage our synergies to maximize stakeholder value", "To Plain English", "general", "mid"],
["Let's circle back on the deliverables", "To Plain English", "general", "mid"],
]
example_cols = st.columns(len(examples))
for i, (text, ex_mode, ex_domain, ex_seniority) in enumerate(examples):
with example_cols[i]:
if st.button(f"Example {i+1}", key=f"example_{i}"):
st.session_state.input_text = text
st.session_state.mode = ex_mode
st.session_state.domain = ex_domain
st.session_state.seniority = ex_seniority
st.rerun()
if __name__ == "__main__":
pass |