Download src/streamlit_app.py from phxdev/corporate-speak-translator: direct link, hf CLI and curl.
- Browser
- Download file 14.2 kB
-
https://huggingface.co/spaces/phxdev/corporate-speak-translator/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/phxdev/corporate-speak-translator/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/phxdev/corporate-speak-translator/resolve/main/src/streamlit_app.py
14.2 kB
| 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 |