SmokeyBandit commited on
Commit
bb469d7
·
verified ·
1 Parent(s): 701de7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -194
app.py CHANGED
@@ -4,16 +4,108 @@ import requests
4
  from datetime import datetime, timedelta
5
  import logging
6
  import random
 
 
 
 
 
7
 
8
  # =============================================================================
9
- # Setup Logging
10
  # =============================================================================
11
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
12
 
 
 
 
 
 
13
  # =============================================================================
14
- # Helper Functions: Interactive Chart Generators
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # =============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
17
  def create_performance_comparison():
18
  """
19
  Creates a performance comparison chart showing current (2GB VRAM) capabilities
@@ -107,7 +199,6 @@ def create_earnings_history():
107
  def calculate_loan_schedule(loan_amount=3000, interest_rate=5.0):
108
  """
109
  Calculates the loan repayment schedule given an investment amount and interest rate.
110
- Returns a formatted string detailing monthly payments and timelines.
111
  """
112
  try:
113
  amount = float(loan_amount)
@@ -145,42 +236,6 @@ def calculate_loan_schedule(loan_amount=3000, interest_rate=5.0):
145
  except ValueError:
146
  return "Please enter valid numbers for the loan calculation."
147
 
148
- def create_detailed_financial_projection():
149
- """
150
- Creates a detailed 12-month financial projection chart with three scenarios:
151
- worst-case, expected, and best-case revenue paths.
152
- """
153
- months = ['Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb']
154
- base_revenue = 1000
155
- worst_case = [base_revenue * (1 + 0.05) ** i for i in range(len(months))]
156
- expected = [base_revenue * (1 + 0.10) ** i for i in range(len(months))]
157
- best_case = [base_revenue * (1 + 0.20) ** i for i in range(len(months))]
158
-
159
- fig = go.Figure()
160
- fig.add_trace(go.Scatter(
161
- x=months, y=worst_case, name='Worst Case',
162
- line={'color': '#FF6B6B', 'width': 2, 'dash': 'dot'}
163
- ))
164
- fig.add_trace(go.Scatter(
165
- x=months, y=expected, name='Expected',
166
- line={'color': '#94A3B8', 'width': 3}
167
- ))
168
- fig.add_trace(go.Scatter(
169
- x=months, y=best_case, name='Best Case',
170
- line={'color': '#2563EB', 'width': 3, 'dash': 'dash'}
171
- ))
172
-
173
- fig.update_layout(
174
- title={'text': '12-Month Financial Projection', 'font': {'size': 24}},
175
- xaxis_title='Month',
176
- yaxis_title='Revenue (USD)',
177
- plot_bgcolor='white',
178
- font={'family': 'Arial', 'size': 14},
179
- legend={'orientation': 'h', 'x': 0.3, 'y': 1.1}
180
- )
181
- logging.debug("Detailed financial projection chart created.")
182
- return fig
183
-
184
  def create_project_timeline():
185
  """
186
  Creates a timeline chart showing key project milestones.
@@ -189,8 +244,12 @@ def create_project_timeline():
189
  dates = ["2025-03-01", "2025-04-15", "2025-06-01", "2025-08-01", "2025-10-01", "2025-12-01"]
190
 
191
  fig = go.Figure(data=go.Scatter(
192
- x=dates, y=list(range(len(milestones))), mode="markers+text",
193
- text=milestones, textposition="top center", marker=dict(size=12, color="#2563EB")
 
 
 
 
194
  ))
195
  fig.update_layout(
196
  title="Project Timeline & Milestones",
@@ -206,7 +265,6 @@ def create_project_timeline():
206
  # =============================================================================
207
  # Helper Functions: Textual Content for Pitch Deck
208
  # =============================================================================
209
-
210
  def display_tech_stack():
211
  """
212
  Returns a Markdown string detailing the technical stack and tools used.
@@ -289,7 +347,7 @@ def display_personal_note():
289
  - Create both proprietary and open source RAG systems.
290
  - Operate a marketing advertising firm with automated agents.
291
 
292
- This GPU upgrade is not just a hardware upgrade—its the key to turning my passion into a sustainable business
293
  that repays your investment and makes you proud.
294
  """
295
  return personal_note
@@ -511,7 +569,37 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
511
  gr.Markdown(display_pitch_deck_overview())
512
 
513
  # -------------------------------------------------------------------------
514
- # Tab 5: Project Timeline & Milestones
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
  # -------------------------------------------------------------------------
516
  with gr.TabItem("📅 Project Timeline & Milestones"):
517
  gr.Markdown("""
@@ -529,7 +617,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
529
  """)
530
 
531
  # -------------------------------------------------------------------------
532
- # Tab 6: From the Heart & Contact
533
  # -------------------------------------------------------------------------
534
  with gr.TabItem("💝 From the Heart"):
535
  gr.Markdown(display_personal_note())
@@ -539,9 +627,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
539
  - **LinkedIn:** <a href="https://www.linkedin.com/in/waynesletcher/" target="_blank" style="color: #2563EB;">Wayne Sletcher</a>
540
  - **Website:** <a href="https://www.sletchersystems.com/" target="_blank" style="color: #2563EB;">sletchersystems.com</a>
541
  """)
542
-
543
  # -------------------------------------------------------------------------
544
- # Tab 7: SaaS Solutions, Systems & Revenue Model
545
  # -------------------------------------------------------------------------
546
  with gr.TabItem("🖥️ SaaS Solutions & Revenue Model"):
547
  gr.Markdown("""
@@ -583,8 +671,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
583
  # - Company Purpose, Problem, Solution, Why Now, Market Size, Competition,
584
  # Product, Business Model, Team, and Financials
585
  # - An in-depth look at my technical stack and current projects
 
586
  # - A project timeline and milestones for future growth
587
- # - A heartfelt personal note aimed at making Dad proud
588
  # - Persistent call-to-action with contact details (email, LinkedIn, website)
589
  #
590
  # Future enhancements may include:
@@ -597,152 +686,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
597
  #
598
  # =============================================================================
599
  #
600
- #
601
- #
602
- #
603
- #
604
- #
605
- #
606
- #
607
- #
608
- #
609
- #
610
- #
611
- #
612
- #
613
- #
614
- #
615
- #
616
- #
617
- #
618
- #
619
- #
620
- #
621
- #
622
- #
623
- #
624
- #
625
- #
626
- #
627
- #
628
- #
629
- #
630
- #
631
- #
632
- #
633
- #
634
- #
635
- #
636
- #
637
- #
638
- #
639
- #
640
- #
641
- #
642
- #
643
- #
644
- #
645
- #
646
- #
647
- #
648
- #
649
- #
650
- #
651
- #
652
- #
653
- #
654
- #
655
- #
656
- #
657
- #
658
- #
659
- #
660
- #
661
- #
662
- #
663
- #
664
- #
665
- #
666
- #
667
- #
668
- #
669
- #
670
- #
671
- #
672
- #
673
- #
674
- #
675
- #
676
- #
677
- #
678
- #
679
- #
680
- #
681
- #
682
- #
683
- #
684
- #
685
- #
686
- #
687
- #
688
- #
689
- #
690
- #
691
- #
692
- #
693
- #
694
- #
695
- #
696
- #
697
- #
698
- #
699
- #
700
- #
701
- #
702
- #
703
- #
704
- #
705
- #
706
- #
707
- #
708
- #
709
- #
710
- #
711
- #
712
- #
713
- #
714
- #
715
- #
716
- #
717
- #
718
- #
719
- #
720
- #
721
- #
722
- #
723
- #
724
- #
725
- #
726
- #
727
- #
728
- #
729
- #
730
- #
731
- #
732
- #
733
- #
734
- #
735
- #
736
- #
737
- #
738
- #
739
- #
740
- #
741
- #
742
- #
743
- #
744
- #
745
- #
746
  # =============================================================================
747
  # End of File
748
  # =============================================================================
 
4
  from datetime import datetime, timedelta
5
  import logging
6
  import random
7
+ from transformers import pipeline
8
+ from huggingface_hub import InferenceClient
9
+ from PIL import Image
10
+ import io
11
+ import os
12
 
13
  # =============================================================================
14
+ # Setup Logging and API Keys
15
  # =============================================================================
16
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
17
 
18
+ # Image Generation Setup
19
+ API_KEY = os.getenv("HF_API_TOKEN")
20
+ MODEL_NAME = "black-forest-labs/FLUX.1-dev"
21
+ client = InferenceClient(api_key=API_KEY)
22
+
23
  # =============================================================================
24
+ # Load In-House Hugging Face Models for AI Agents with Fallbacks
25
+ # =============================================================================
26
+ try:
27
+ summarizer = pipeline("summarization", model="myorg/inhouse-summarizer")
28
+ logging.info("Loaded in-house summarizer.")
29
+ except Exception as e:
30
+ logging.error("In-house summarizer not found, falling back: %s", e)
31
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
32
+
33
+ try:
34
+ research_generator = pipeline("text-generation", model="myorg/inhouse-research", max_length=100)
35
+ logging.info("Loaded in-house research generator.")
36
+ except Exception as e:
37
+ logging.error("In-house research generator not found, falling back: %s", e)
38
+ research_generator = pipeline("text-generation", model="gpt2", max_length=100)
39
+
40
+ try:
41
+ planner_generator = pipeline("text-generation", model="myorg/inhouse-planner", max_length=150)
42
+ logging.info("Loaded in-house planner generator.")
43
+ except Exception as e:
44
+ logging.error("In-house planner generator not found, falling back: %s", e)
45
+ planner_generator = pipeline("text-generation", model="gpt2", max_length=150)
46
+
47
+ # =============================================================================
48
+ # In-House Agent Functions
49
+ # =============================================================================
50
+ def report_agent(data):
51
+ """
52
+ Generates a summary report using the in-house summarizer model.
53
+ """
54
+ if not data or len(data.strip()) == 0:
55
+ return "Please provide input text for summarization."
56
+ try:
57
+ summary = summarizer(data, max_length=130, min_length=30, do_sample=False)
58
+ logging.debug("Summary generated using in-house summarizer.")
59
+ return summary[0]['summary_text']
60
+ except Exception as e:
61
+ logging.error("Error generating summary: %s", e)
62
+ return "Error generating summary."
63
+
64
+ def planning_agent(goal):
65
+ """
66
+ Generates a detailed action plan based on the provided goal using the in-house planner model.
67
+ """
68
+ if not goal or len(goal.strip()) == 0:
69
+ return "Please provide a goal for planning."
70
+ try:
71
+ plan = planner_generator(goal, max_length=150, num_return_sequences=1)
72
+ logging.debug("Plan generated using in-house planner.")
73
+ return plan[0]['generated_text']
74
+ except Exception as e:
75
+ logging.error("Error generating plan: %s", e)
76
+ return "Error generating plan."
77
+
78
+ def research_agent(query):
79
+ """
80
+ Generates research insights based on the provided query using the in-house research generator.
81
+ """
82
+ if not query or len(query.strip()) == 0:
83
+ return "Please provide a research query."
84
+ try:
85
+ result = research_generator(query, max_length=100, num_return_sequences=1)
86
+ logging.debug("Research output generated using in-house research model.")
87
+ return result[0]['generated_text']
88
+ except Exception as e:
89
+ logging.error("Error generating research output: %s", e)
90
+ return "Error generating research output."
91
+
92
  # =============================================================================
93
+ # Image Generation Function
94
+ # =============================================================================
95
+ def generate_image(prompt):
96
+ """Generate an image from a text prompt using Hugging Face API."""
97
+ try:
98
+ image = client.text_to_image(prompt, model=MODEL_NAME)
99
+ img_byte_array = io.BytesIO()
100
+ image.save(img_byte_array, format="PNG")
101
+ img_byte_array.seek(0)
102
+ return image
103
+ except Exception as e:
104
+ return f"Error generating image: {e}"
105
 
106
+ # =============================================================================
107
+ # Helper Functions: Interactive Chart Generators
108
+ # =============================================================================
109
  def create_performance_comparison():
110
  """
111
  Creates a performance comparison chart showing current (2GB VRAM) capabilities
 
199
  def calculate_loan_schedule(loan_amount=3000, interest_rate=5.0):
200
  """
201
  Calculates the loan repayment schedule given an investment amount and interest rate.
 
202
  """
203
  try:
204
  amount = float(loan_amount)
 
236
  except ValueError:
237
  return "Please enter valid numbers for the loan calculation."
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  def create_project_timeline():
240
  """
241
  Creates a timeline chart showing key project milestones.
 
244
  dates = ["2025-03-01", "2025-04-15", "2025-06-01", "2025-08-01", "2025-10-01", "2025-12-01"]
245
 
246
  fig = go.Figure(data=go.Scatter(
247
+ x=dates,
248
+ y=list(range(len(milestones))),
249
+ mode="markers+text",
250
+ text=milestones,
251
+ textposition="top center",
252
+ marker=dict(size=12, color="#2563EB")
253
  ))
254
  fig.update_layout(
255
  title="Project Timeline & Milestones",
 
265
  # =============================================================================
266
  # Helper Functions: Textual Content for Pitch Deck
267
  # =============================================================================
 
268
  def display_tech_stack():
269
  """
270
  Returns a Markdown string detailing the technical stack and tools used.
 
347
  - Create both proprietary and open source RAG systems.
348
  - Operate a marketing advertising firm with automated agents.
349
 
350
+ This GPU upgrade is not just a hardware upgrade—it's the key to turning my passion into a sustainable business
351
  that repays your investment and makes you proud.
352
  """
353
  return personal_note
 
569
  gr.Markdown(display_pitch_deck_overview())
570
 
571
  # -------------------------------------------------------------------------
572
+ # Tab 5: 🤖 AI Agents
573
+ # -------------------------------------------------------------------------
574
+ with gr.TabItem("🤖 AI Agents"):
575
+ gr.Markdown("""
576
+ ### AI Agent Tools
577
+ Use these tools to generate summaries, action plans, and research insights
578
+ using our in-house Hugging Face models.
579
+ """)
580
+ with gr.Row():
581
+ with gr.Column():
582
+ gr.Markdown("#### Summarizer")
583
+ summarizer_input = gr.Textbox(label="Enter text to summarize", placeholder="Paste text here...", lines=5)
584
+ summarizer_output = gr.Textbox(label="Summary", lines=5)
585
+ summarizer_button = gr.Button("Generate Summary")
586
+ summarizer_button.click(report_agent, inputs=[summarizer_input], outputs=[summarizer_output])
587
+ with gr.Column():
588
+ gr.Markdown("#### Planner")
589
+ planner_input = gr.Textbox(label="Enter goal or task", placeholder="Describe your goal...", lines=5)
590
+ planner_output = gr.Textbox(label="Action Plan", lines=5)
591
+ planner_button = gr.Button("Generate Plan")
592
+ planner_button.click(planning_agent, inputs=[planner_input], outputs=[planner_output])
593
+ with gr.Row():
594
+ with gr.Column():
595
+ gr.Markdown("#### Research Agent")
596
+ research_input = gr.Textbox(label="Enter research query", placeholder="Ask your research question...", lines=5)
597
+ research_output = gr.Textbox(label="Research Insights", lines=5)
598
+ research_button = gr.Button("Generate Research")
599
+ research_button.click(research_agent, inputs=[research_input], outputs=[research_output])
600
+
601
+ # -------------------------------------------------------------------------
602
+ # Tab 6: Project Timeline & Milestones
603
  # -------------------------------------------------------------------------
604
  with gr.TabItem("📅 Project Timeline & Milestones"):
605
  gr.Markdown("""
 
617
  """)
618
 
619
  # -------------------------------------------------------------------------
620
+ # Tab 7: From the Heart & Contact
621
  # -------------------------------------------------------------------------
622
  with gr.TabItem("💝 From the Heart"):
623
  gr.Markdown(display_personal_note())
 
627
  - **LinkedIn:** <a href="https://www.linkedin.com/in/waynesletcher/" target="_blank" style="color: #2563EB;">Wayne Sletcher</a>
628
  - **Website:** <a href="https://www.sletchersystems.com/" target="_blank" style="color: #2563EB;">sletchersystems.com</a>
629
  """)
630
+
631
  # -------------------------------------------------------------------------
632
+ # Tab 8: SaaS Solutions, Systems & Revenue Model
633
  # -------------------------------------------------------------------------
634
  with gr.TabItem("🖥️ SaaS Solutions & Revenue Model"):
635
  gr.Markdown("""
 
671
  # - Company Purpose, Problem, Solution, Why Now, Market Size, Competition,
672
  # Product, Business Model, Team, and Financials
673
  # - An in-depth look at my technical stack and current projects
674
+ # - A new tab ("🤖 AI Agents") for in-house NLP tasks: summarization, planning, research
675
  # - A project timeline and milestones for future growth
676
+ # - A heartfelt personal note aimed at making Dad proud, along with contact details
677
  # - Persistent call-to-action with contact details (email, LinkedIn, website)
678
  #
679
  # Future enhancements may include:
 
686
  #
687
  # =============================================================================
688
  #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689
  # =============================================================================
690
  # End of File
691
  # =============================================================================