phxdev commited on
Commit
4c73b94
·
verified ·
1 Parent(s): 30370bb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +104 -44
src/streamlit_app.py CHANGED
@@ -1,56 +1,112 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- from peft import PeftModel
4
- import torch
5
  from PIL import Image, ImageDraw, ImageFont
6
  import io
7
- import base64
8
  import textwrap
9
  import urllib.parse
10
 
11
- @st.cache_resource
12
- def load_model():
13
- """Load and cache the model"""
14
- base_model = "mistralai/Mistral-7B-Instruct-v0.2"
15
- adapter_model = "phxdev/corporate-synergy-bot-7b"
16
-
17
- tokenizer = AutoTokenizer.from_pretrained(base_model)
18
- model = AutoModelForCausalLM.from_pretrained(
19
- base_model,
20
- torch_dtype=torch.float16,
21
- device_map="auto"
22
- )
23
- model = PeftModel.from_pretrained(model, adapter_model)
24
- return tokenizer, model
25
-
26
- tokenizer, model = load_model()
27
 
28
  def transform_text(text, mode="To Corporate", domain="general", seniority="mid"):
29
- """Transform text between casual and corporate speak"""
30
 
31
  if mode == "To Corporate":
32
- instruction = f"Transform to {domain} corporate speak (seniority: {seniority})"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  else:
34
- instruction = "Translate corporate speak to plain English"
35
-
36
- prompt = f"""### Instruction: {instruction}
37
- ### Input: {text}
38
- ### Response:"""
39
-
40
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
41
-
42
- with torch.no_grad():
43
- outputs = model.generate(
44
- **inputs,
45
- max_new_tokens=150,
46
- temperature=0.7,
47
- top_p=0.9,
48
- do_sample=True,
49
- pad_token_id=tokenizer.eos_token_id
50
- )
51
-
52
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
53
- return response.split("### Response:")[-1].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  def create_shareable_card(input_text, output_text, mode, domain, seniority):
56
  """Create a shareable image card with the transformation"""
@@ -120,7 +176,7 @@ def create_shareable_card(input_text, output_text, mode, domain, seniority):
120
  y_pos += 25
121
 
122
  # Footer
123
- footer_text = "Generated with Corporate Synergy Bot 7B"
124
  footer_bbox = draw.textbbox((0, 0), footer_text, font=small_font)
125
  footer_width = footer_bbox[2] - footer_bbox[0]
126
  draw.text(((width - footer_width) // 2, height - 40), footer_text, fill=secondary_color, font=small_font)
@@ -158,6 +214,10 @@ st.set_page_config(
158
  )
159
 
160
  st.title("🏢 Corporate Synergy Bot 7B")
 
 
 
 
161
  st.markdown("""
162
  Transform casual language into professional corporate communication or decode corporate jargon back to plain English.
163
 
@@ -320,4 +380,4 @@ for i, (text, ex_mode, ex_domain, ex_seniority) in enumerate(examples):
320
  st.rerun()
321
 
322
  if __name__ == "__main__":
323
- pass
 
1
  import streamlit as st
 
 
 
2
  from PIL import Image, ImageDraw, ImageFont
3
  import io
 
4
  import textwrap
5
  import urllib.parse
6
 
7
+ # Demo mode for deployment environments without heavy ML dependencies
8
+ DEMO_MODE = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def transform_text(text, mode="To Corporate", domain="general", seniority="mid"):
11
+ """Demo transformation without ML model"""
12
 
13
  if mode == "To Corporate":
14
+ # Enhanced corporate transformations
15
+ corporate_map = {
16
+ "let's meet": "I would appreciate the opportunity to sync up",
17
+ "meet tomorrow": "sync up tomorrow to align on our objectives",
18
+ "i need help": "I require assistance with these deliverables",
19
+ "need help with": "require support to optimize",
20
+ "good job": "Excellent execution on this initiative",
21
+ "great work": "Outstanding performance on the deliverables",
22
+ "what's up": "I hope this message finds you well",
23
+ "how's it going": "I wanted to touch base on current progress",
24
+ "thanks": "I appreciate your collaboration",
25
+ "thank you": "I'm grateful for your partnership",
26
+ "ok": "Understood, I'll proceed accordingly",
27
+ "sure": "Certainly, I'd be happy to assist",
28
+ "got it": "I acknowledge and will action accordingly",
29
+ "my bad": "I apologize for the oversight",
30
+ "sorry": "I regret any inconvenience",
31
+ "asap": "at your earliest convenience",
32
+ "right away": "with expedited priority",
33
+ "fyi": "for your awareness",
34
+ "by the way": "additionally, I wanted to mention",
35
+ "btw": "furthermore",
36
+ "let's start": "let's operationalize this initiative",
37
+ "let's begin": "let's commence the deliverables",
38
+ "fix this": "address these challenges",
39
+ "problem": "opportunity for improvement",
40
+ "issue": "consideration that requires attention",
41
+ "busy": "operating at full bandwidth",
42
+ "swamped": "currently resource-constrained"
43
+ }
44
+
45
+ result = text.lower()
46
+ for casual, corporate in corporate_map.items():
47
+ if casual in result:
48
+ result = result.replace(casual, corporate)
49
+
50
+ # Add domain-specific enhancements
51
+ if domain == "tech":
52
+ if "project" in result:
53
+ result = result.replace("project", "sprint initiative")
54
+ result += " leveraging our agile methodology"
55
+ elif domain == "finance":
56
+ if "money" in result:
57
+ result = result.replace("money", "capital allocation")
58
+ result += " ensuring regulatory compliance"
59
+ elif domain == "consulting":
60
+ if "idea" in result:
61
+ result = result.replace("idea", "strategic recommendation")
62
+ result += " aligned with best practices"
63
+ elif domain == "healthcare":
64
+ result += " maintaining patient-centered focus"
65
+
66
+ # Seniority-based adjustments
67
+ if seniority == "executive":
68
+ result = "From a strategic perspective, " + result
69
+ elif seniority == "senior":
70
+ result = "Based on my experience, " + result
71
+
72
+ return result.capitalize()
73
+
74
  else:
75
+ # Enhanced reverse transformation
76
+ plain_map = {
77
+ "leverage": "use",
78
+ "synergize": "work together",
79
+ "operationalize": "start",
80
+ "deliverables": "work",
81
+ "action items": "tasks",
82
+ "circle back": "talk later",
83
+ "touch base": "meet",
84
+ "deep dive": "look closely",
85
+ "bandwidth": "time",
86
+ "stakeholder": "person involved",
87
+ "paradigm shift": "big change",
88
+ "low-hanging fruit": "easy wins",
89
+ "move the needle": "make a difference",
90
+ "game changer": "big improvement",
91
+ "best practices": "good ways",
92
+ "ecosystem": "environment",
93
+ "scalable": "can grow",
94
+ "robust": "strong",
95
+ "streamline": "simplify",
96
+ "optimize": "improve",
97
+ "facilitate": "help",
98
+ "utilize": "use",
99
+ "implement": "do",
100
+ "collaborate": "work together",
101
+ "ideate": "think of ideas",
102
+ "incentivize": "encourage"
103
+ }
104
+
105
+ result = text.lower()
106
+ for corporate, plain in plain_map.items():
107
+ result = result.replace(corporate, plain)
108
+
109
+ return result.capitalize()
110
 
111
  def create_shareable_card(input_text, output_text, mode, domain, seniority):
112
  """Create a shareable image card with the transformation"""
 
176
  y_pos += 25
177
 
178
  # Footer
179
+ footer_text = "Generated with Corporate Synergy Bot 7B (Demo)"
180
  footer_bbox = draw.textbbox((0, 0), footer_text, font=small_font)
181
  footer_width = footer_bbox[2] - footer_bbox[0]
182
  draw.text(((width - footer_width) // 2, height - 40), footer_text, fill=secondary_color, font=small_font)
 
214
  )
215
 
216
  st.title("🏢 Corporate Synergy Bot 7B")
217
+
218
+ if DEMO_MODE:
219
+ st.warning("⚠️ Demo Mode: Using rule-based transformations. Full AI model requires more resources.")
220
+
221
  st.markdown("""
222
  Transform casual language into professional corporate communication or decode corporate jargon back to plain English.
223
 
 
380
  st.rerun()
381
 
382
  if __name__ == "__main__":
383
+ pass