|
import gradio as gr |
|
import plotly.graph_objects as go |
|
import requests |
|
from bs4 import BeautifulSoup |
|
from duckduckgo_search import DDGS |
|
from transformers import pipeline |
|
from datetime import datetime, timedelta |
|
import logging |
|
import random |
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') |
|
|
|
|
|
try: |
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
report_summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") |
|
logging.info("Transformer models loaded successfully.") |
|
except Exception as e: |
|
logging.error("Error loading transformer pipelines: %s", e) |
|
summarizer = None |
|
report_summarizer = None |
|
|
|
|
|
|
|
|
|
|
|
def create_performance_comparison(): |
|
""" |
|
Generates a bar chart comparing current setup with upgraded GPU. |
|
""" |
|
categories = [ |
|
'AI Model Loading', |
|
'VS Code Extensions', |
|
'Local Offline AI Assistants', |
|
'Image Processing', |
|
'Multi-tasking', |
|
'Large Dataset Analysis' |
|
] |
|
current_values = [20, 15, 10, 18, 25, 12] |
|
potential_values = [100, 100, 100, 100, 100, 100] |
|
|
|
fig = go.Figure(data=[ |
|
go.Bar(name='Current Setup (2GB VRAM)', x=categories, y=current_values, marker_color='#2D3748'), |
|
go.Bar(name='Potential (Upgraded GPU)', x=categories, y=potential_values, marker_color='#4A5568') |
|
]) |
|
|
|
fig.update_layout( |
|
title={'text': 'Performance Comparison Analysis', 'font': {'size': 24}}, |
|
barmode='group', |
|
yaxis_title='Relative Performance (%)', |
|
plot_bgcolor='white', |
|
font={'family': 'Arial', 'size': 14}, |
|
legend={'orientation': 'h', 'x': 0.2, 'y': 1.1} |
|
) |
|
return fig |
|
|
|
def create_roi_projection(): |
|
""" |
|
Creates a 24-month ROI projection chart. |
|
""" |
|
months = list(range(1, 25)) |
|
base_revenue = 1000 |
|
current_growth_rate = 0.1 |
|
upgraded_growth_rate = 0.25 |
|
|
|
current_revenue = [base_revenue * (1 + current_growth_rate) ** i for i in range(len(months))] |
|
projected_revenue = [base_revenue * (1 + upgraded_growth_rate) ** i for i in range(len(months))] |
|
|
|
total_investment = 3000 |
|
additional_revenue = sum(projected_revenue) - sum(current_revenue) |
|
roi_percentage = (additional_revenue / total_investment) * 100 |
|
|
|
fig = go.Figure() |
|
fig.add_trace(go.Scatter( |
|
x=months, y=current_revenue, name='Current Revenue', |
|
line={'color': '#2D3748', 'width': 3} |
|
)) |
|
fig.add_trace(go.Scatter( |
|
x=months, y=projected_revenue, name='Projected Revenue with GPU Upgrade', |
|
line={'color': '#4A5568', 'width': 3} |
|
)) |
|
|
|
fig.update_layout( |
|
title={'text': f'24-Month Revenue Projection (ROI: {roi_percentage:.1f}%)', 'font': {'size': 24}}, |
|
xaxis_title='Month', |
|
yaxis_title='Revenue (USD)', |
|
plot_bgcolor='white', |
|
font={'family': 'Arial', 'size': 14}, |
|
legend={'orientation': 'h', 'x': 0.3, 'y': 1.1} |
|
) |
|
return fig |
|
|
|
def calculate_loan_details(loan_amount, interest_rate=5.0): |
|
""" |
|
Calculates detailed monthly loan repayment schedule. |
|
""" |
|
try: |
|
amount = float(loan_amount) |
|
annual_rate = float(interest_rate) / 100 |
|
monthly_rate = annual_rate / 12 |
|
grace_period = 3 |
|
repayment_period = 12 |
|
|
|
monthly_payment = amount * (monthly_rate * (1 + monthly_rate) ** repayment_period) / ((1 + monthly_rate) ** repayment_period - 1) |
|
|
|
schedule = "π **Detailed Loan Repayment Schedule**\n\n" |
|
schedule += f"**π° Loan Amount:** ${amount:,.2f}\n" |
|
schedule += f"**β³ Grace Period:** {grace_period} months\n" |
|
schedule += f"**π Annual Interest Rate:** {interest_rate}%\n" |
|
schedule += f"**π΅ Monthly Payment (starting month {grace_period + 1}):** ${monthly_payment:,.2f}\n\n" |
|
|
|
remaining_balance = amount |
|
total_interest = 0 |
|
current_date = datetime.now() |
|
|
|
schedule += "**Monthly Breakdown:**\n" |
|
for month in range(1, repayment_period + grace_period + 1): |
|
date = current_date + timedelta(days=30 * month) |
|
if month <= grace_period: |
|
schedule += f"- {date.strftime('%B %Y')}: Grace Period (No Payment)\n" |
|
else: |
|
interest = remaining_balance * monthly_rate |
|
principal = monthly_payment - interest |
|
remaining_balance -= principal |
|
total_interest += interest |
|
schedule += f"- {date.strftime('%B %Y')}: ${monthly_payment:,.2f} (Principal: ${principal:,.2f}, Interest: ${interest:,.2f})\n" |
|
|
|
schedule += f"\n**π Total Interest Paid:** ${total_interest:,.2f}" |
|
return schedule |
|
except ValueError: |
|
return "β οΈ Please enter a valid loan amount" |
|
|
|
|
|
|
|
|
|
|
|
def robust_web_scrape_agent(url): |
|
""" |
|
Extracts content from URL using multiple user-agents and fallback methods. |
|
""" |
|
user_agents = [ |
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/115.0.0.0 Safari/537.36", |
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 Version/15.1 Safari/605.1.15", |
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/114.0.0.0 Safari/537.36", |
|
] |
|
headers = {'User-Agent': random.choice(user_agents)} |
|
|
|
try: |
|
response = requests.get(url, headers=headers, timeout=10) |
|
if response.status_code != 200: |
|
return f"Error: Received status code {response.status_code}" |
|
|
|
soup = BeautifulSoup(response.text, "html.parser") |
|
for tag in soup(["script", "style", "noscript"]): |
|
tag.decompose() |
|
text = soup.get_text(separator="\n").strip() |
|
|
|
if not text or len(text) < 200: |
|
try: |
|
from readability import Document |
|
doc = Document(response.text) |
|
extracted_html = doc.summary() |
|
fallback_soup = BeautifulSoup(extracted_html, "html.parser") |
|
text = fallback_soup.get_text(separator="\n").strip() |
|
except ImportError: |
|
logging.error("Readability module not available.") |
|
except Exception as fallback_error: |
|
logging.error("Fallback extraction failed: %s", fallback_error) |
|
|
|
return text if text and len(text) >= 200 else "No substantial content found." |
|
except Exception as e: |
|
return f"Error during scraping: {e}" |
|
|
|
def research_agent(query): |
|
""" |
|
Performs web search using DuckDuckGo. |
|
""" |
|
try: |
|
with DDGS() as ddgs: |
|
results = ddgs.text(query, max_results=5) |
|
if results: |
|
return "\n\n".join([f"**{result.get('title', 'No Title')}**:\n{result.get('href', 'No URL')}" for result in results]) |
|
return "No results found." |
|
except Exception as e: |
|
return f"Error during research: {e}" |
|
|
|
def report_agent(data): |
|
""" |
|
Generates summary report using transformer model. |
|
""" |
|
try: |
|
if not report_summarizer: |
|
return "Report summarization is not available." |
|
if len(data.split()) < 30: |
|
return "Input text is too short for summarization." |
|
summary = report_summarizer(data, max_length=130, min_length=30, do_sample=False) |
|
return summary[0]['summary_text'] |
|
except Exception as e: |
|
return f"Error during report generation: {e}" |
|
|
|
|
|
|
|
|
|
|
|
def create_earnings_plot(): |
|
""" |
|
Plots earnings history. |
|
""" |
|
dates = ["2024-12-10", "2024-12-17", "2024-12-24", "2024-12-31", "2025-01-07", |
|
"2025-01-14", "2025-01-21", "2025-01-28", "2025-02-04", "2025-02-11"] |
|
earnings = [156.02, 73.10, 97.07, 116.11, 79.05, 86.62, 54.57, 86.36, 61.50, 79.18] |
|
|
|
fig = go.Figure(data=go.Scatter( |
|
x=dates, y=earnings, mode='lines+markers', |
|
line=dict(color='#4A5568', width=3) |
|
)) |
|
fig.update_layout( |
|
title={'text': 'Personal Earnings History', 'font': {'size': 24}}, |
|
xaxis_title='Date', |
|
yaxis_title='Earnings (USD)', |
|
plot_bgcolor='white', |
|
font={'family': 'Arial', 'size': 14} |
|
) |
|
return fig |
|
|
|
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Default( |
|
primary_hue="slate", |
|
secondary_hue="slate", |
|
neutral_hue="slate", |
|
font=["Arial", "sans-serif"] |
|
)) as demo: |
|
|
|
gr.HTML(""" |
|
<div style="background: #2D3748; color: white; text-align: center; padding: 10px; font-size: 16px;"> |
|
Support this project on <a href="https://ko-fi.com/waynesletcher" target="_blank" style="color: #A0AEC0; text-decoration: underline;">Ko-fi</a> |
|
</div> |
|
""") |
|
|
|
|
|
gr.HTML(""" |
|
<div style="background: linear-gradient(90deg, #2D3748, #4A5568); padding: 20px; text-align: center; color: white;"> |
|
<h1 style="margin: 0; font-size: 36px;">Sletcher Systems: Business Expansion Proposal</h1> |
|
<p style="margin: 10px 0 0; font-size: 18px;">Scaling AI Innovation through Strategic Investment</p> |
|
</div> |
|
""") |
|
|
|
with gr.Tabs(): |
|
|
|
with gr.TabItem("π Executive Summary"): |
|
gr.Markdown(""" |
|
### Vision & Opportunity |
|
Sletcher Systems aims to scale our AI development capabilities through strategic GPU infrastructure investment. |
|
|
|
### Current Challenges |
|
- Limited by 2GB VRAM setup |
|
- Running at capacity with current projects |
|
- Unable to take on larger clients |
|
|
|
### Investment Request |
|
- Amount: $3,000 for GPU upgrade |
|
- ROI Timeline: 12-24 months |
|
- Clear path to expanded services |
|
""") |
|
gr.Plot(value=create_performance_comparison()) |
|
|
|
|
|
with gr.TabItem("π Market Analysis"): |
|
with gr.Row(): |
|
with gr.Column(): |
|
gr.Markdown(""" |
|
### Target Market |
|
- Small to medium businesses |
|
- Educational institutions |
|
- Software development firms |
|
|
|
### Market Size |
|
- Local AI services market: $50M annually |
|
- 25% YoY growth |
|
- Untapped potential |
|
""") |
|
with gr.Column(): |
|
gr.Plot(value=create_roi_projection()) |
|
|
|
|
|
with gr.TabItem("π» Technical Stack"): |
|
gr.Markdown(""" |
|
### Current Stack |
|
- Python, TensorFlow, PyTorch |
|
- Web Development (React, Next.js) |
|
- Cloud Infrastructure |
|
|
|
### Planned Expansion |
|
- Advanced AI Model Training |
|
- Real-time Processing |
|
- Expanded Service Offerings |
|
""") |
|
with gr.Row(): |
|
demo_url = gr.Textbox(label="Analyze Website", value="https://sletchersystems.com") |
|
demo_output = gr.Textbox(label="Analysis Results", lines=10) |
|
demo_button = gr.Button("π Analyze") |
|
demo_button.click(robust_web_scrape_agent, inputs=demo_url, outputs=demo_output) |
|
|
|
|
|
with gr.TabItem("π° Financial Plan"): |
|
with gr.Row(): |
|
loan_amount = gr.Number(label="Investment Amount ($)", value=3000) |
|
interest_rate = gr.Slider(label="Annual Interest Rate (%)", value=5) |
|
calculate_button = gr.Button("Calculate Repayment Schedule") |
|
schedule_output = gr.Textbox(label="Repayment Details", lines=15) |
|
calculate_button.click(calculate_loan_details, inputs=[loan_amount, interest_rate], outputs=schedule_output) |
|
gr.Plot(value=create_earnings_plot()) |
|
|
|
|
|
with gr.TabItem("π¬ R&D"): |
|
with gr.Row(): |
|
research_query = gr.Textbox(label="Research Topic", placeholder="Enter research topic...") |
|
research_output = gr.Textbox(label="Research Results", lines=10) |
|
research_button = gr.Button("π Research") |
|
research_button.click(research_agent, inputs=research_query, outputs=research_output) |
|
with gr.Row(): |
|
report_input = gr.Textbox(label="Report Text", placeholder="Enter report text...") |
|
report_output = gr.Textbox(label="Report Summary", lines=10) |
|
report_button = gr.Button("π Summarize Report") |
|
report_button.click(report_agent, inputs=report_input, outputs=report_output) |
|
|
|
with gr.TabItem("π
Timeline"): |
|
gr.Markdown(""" |
|
### Phase 1: Infrastructure (Month 1) |
|
- GPU procurement and setup |
|
- System integration |
|
- Initial testing |
|
|
|
### Phase 2: Service Expansion (Months 2-3) |
|
- New service rollout |
|
- Client outreach |
|
- Project pipeline development |
|
|
|
### Phase 3: Growth (Months 4-12) |
|
- Market expansion |
|
- Team growth |
|
- Revenue scaling |
|
""") |
|
|
|
demo.launch(share=True) |
|
|