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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

import gradio as gr
import pandas as pd
import numpy as np
import io
import json
import time
import random
from datetime import datetime
import plotly.graph_objects as go
import plotly.express as px
import spaces

# Mock functions to simulate the FastAPI web scraping project
class WebScrapingSimulator:
    def __init__(self):
        self.demo_results = {
            "https://example.com": "OTHER",
            "https://news.bbc.com": "NEWS/BLOG", 
            "https://github.com": "OTHER",
            "https://stackoverflow.com": "OTHER",
            "https://amazon.com": "E-COMMERCE",
            "https://techcrunch.com": "NEWS/BLOG",
            "https://shopify.com": "E-COMMERCE",
            "https://python.org": "OTHER"
        }

    
    def simulate_scraping(self, urls_text, progress=gr.Progress()):
        if not urls_text.strip():
            return "Please enter at least one URL", None, ""
    
        urls = [url.strip() for url in urls_text.split('\n') if url.strip()]
        if not urls:
            return "Please enter valid URLs", None, ""
    
        results = {}
        progress_bar = progress.tqdm(urls, desc="Processing URLs")
    
        for url in progress_bar:
            time.sleep(1)
            if url in self.demo_results:
                classification = self.demo_results[url]
            else:
                classification = random.choice(["OTHER", "NEWS/BLOG", "E-COMMERCE"])
    
            results[url] = {
                "url": url,
                "classification": classification,
                "confidence": round(random.uniform(0.75, 0.99), 2),
                "processed_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            }
    
        # Format results for display
        results_text = "Classification Results:\n\n"
        for url, data in results.items():
            results_text += f"URL: {url}\n"
            results_text += f"Classification: {data['classification']}\n"
            results_text += f"Confidence: {data['confidence']}\n"
            results_text += f"Processed: {data['processed_at']}\n"
            results_text += "-" * 50 + "\n"
    
        # # βœ… Create in-memory JSON file for download
        # json_bytes = json.dumps(results, indent=2).encode('utf-8')
        # file_obj = io.BytesIO(json_bytes)
        # file_obj.name = "scraping_results.json"  # optional but helpful

        # return results_text, ("scraping_results.json", json_bytes), f"Processed {len(results)} URLs successfully!"
        return results_text, f"Processed {len(results)} URLs successfully!"
# Computer Vision simulator
@spaces.GPU
def simulate_cv_processing(image, model_type):
    """Simulate computer vision processing"""
    if image is None:
        return "Please upload an image", ""

    time.sleep(2)  # Simulate processing

    if model_type == "Face Detection":
        result = "Detected 2 faces in the image\nConfidence scores: 0.94, 0.87\nBounding boxes: [(120,150,200,240), (300,180,380,270)]"
    elif model_type == "Object Detection":
        result = "Detected objects:\n- Person (confidence: 0.91)\n- Car (confidence: 0.84)\n- Tree (confidence: 0.76)"
    else:  # Image Classification
        result = "Classification results:\n- Dog: 85.3%\n- Golden Retriever: 12.1%\n- Pet: 2.6%"

    status = f"βœ… Image processed successfully using {model_type}"
    return result, status

# Text analysis simulator
@spaces.GPU
def simulate_text_analysis(text, analysis_type):
    """Simulate text analysis"""
    if not text.strip():
        return "Please enter some text to analyze"

    time.sleep(1)  # Simulate processing

    if analysis_type == "Sentiment Analysis":
        sentiment = random.choice(["Positive", "Negative", "Neutral"])
        confidence = round(random.uniform(0.7, 0.95), 2)
        return f"Sentiment: {sentiment}\nConfidence: {confidence}\nText length: {len(text)} characters"

    elif analysis_type == "Summarization":
        # Simple extractive summarization simulation
        sentences = text.split('.')
        summary = '. '.join(sentences[:2]) + '.' if len(sentences) > 1 else text[:100] + "..."
        return f"Summary:\n{summary}\n\nOriginal length: {len(text)} chars\nSummary length: {len(summary)} chars"

    else:  # Named Entity Recognition
        entities = ["OpenAI (ORG)", "San Francisco (LOC)", "2023 (DATE)", "AI (TECH)"]
        return f"Named Entities Found:\n" + "\n".join([f"- {entity}" for entity in entities])

# Data visualization functions
def create_sample_chart(chart_type, data_source="sample"):
    """Create sample charts"""
    if data_source == "sample":
        # Use built-in sample data
        months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
        sales = [4000, 3000, 2000, 2780, 1890, 2390]
        visitors = [2400, 1398, 9800, 3908, 4800, 3800]

        if chart_type == "Line Chart":
            fig = go.Figure()
            fig.add_trace(go.Scatter(x=months, y=sales, name='Sales', mode='lines+markers'))
            fig.add_trace(go.Scatter(x=months, y=visitors, name='Visitors', mode='lines+markers'))
            fig.update_layout(title="Sales & Visitors Trend", xaxis_title="Month", yaxis_title="Count")
            return fig

        elif chart_type == "Bar Chart":
            fig = go.Figure(data=[go.Bar(x=months, y=sales, name='Sales')])
            fig.update_layout(title="Monthly Sales", xaxis_title="Month", yaxis_title="Sales")
            return fig

        else:  # Pie Chart
            fig = go.Figure(data=[go.Pie(labels=months, values=sales)])
            fig.update_layout(title="Sales Distribution by Month")
            return fig

    return go.Figure()

def process_uploaded_csv(file):
    """Process uploaded CSV file"""
    if file is None:
        return "Please upload a CSV file", go.Figure()

    try:
        df = pd.read_csv(file.name)
        preview = df.head().to_string()

        # Create a simple visualization
        if len(df.columns) >= 2:
            fig = px.scatter(df, x=df.columns[0], y=df.columns[1], 
                           title=f"{df.columns[1]} vs {df.columns[0]}")
        else:
            fig = go.Figure()

        return f"CSV loaded successfully!\n\nShape: {df.shape}\nColumns: {list(df.columns)}\n\nPreview:\n{preview}", fig

    except Exception as e:
        return f"Error processing CSV: {str(e)}", go.Figure()

# Initialize the web scraping simulator
scraper = WebScrapingSimulator()

# Custom CSS
custom_css = """
/* Custom styling for the portfolio */
.gradio-container {
    max-width: 1200px !important;
    margin: auto !important;
}

.tab-nav {
    background: linear-gradient(90deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 2rem;
}

.project-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    margin-bottom: 2rem;
}

.tech-badge {
    background: #e0f2fe;
    color: #01579b;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0.25rem;
    display: inline-block;
}

.project-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.status-success {
    color: #059669;
    font-weight: 500;
}

.status-error {
    color: #dc2626;
    font-weight: 500;
}
"""

# Create the main application
def create_portfolio_app():
    with gr.Blocks(css=custom_css, title="AI/ML Developer Portfolio", theme=gr.themes.Soft()) as app:

        gr.HTML("""
        <div class="project-header">
            <h1>πŸ€– AI/ML Developer Portfolio</h1>
            <p>Interactive showcase of machine learning and data science projects</p>
            <p><strong>Specializing in:</strong> Web Scraping β€’ Computer Vision β€’ NLP β€’ MLOps</p>
        </div>
        """)

        with gr.Tabs() as tabs:

            # Home & About Tab
            with gr.Tab("🏠 Home & About"):
                with gr.Row():
                    with gr.Column(scale=2):
                        gr.Markdown("""
                        ## About Me

                        I'm a passionate **Python Developer & Data Scientist** based in **Simferopol, Crimea**, 
                        specializing in building production-ready AI/ML systems. This interactive portfolio 
                        showcases real projects that you can explore and run directly in your browser.

                        ### πŸ”§ Core Technologies
                        """)

                        gr.HTML("""
                        <div style="margin: 1rem 0;">
                            <span class="tech-badge">Python</span>
                            <span class="tech-badge">FastAPI</span>
                            <span class="tech-badge">Gradio</span>
                            <span class="tech-badge">Docker</span>
                            <span class="tech-badge">Redis</span>
                            <span class="tech-badge">PostgreSQL</span>
                            <span class="tech-badge">PyTorch</span>
                            <span class="tech-badge">Hugging Face</span>
                            <span class="tech-badge">OpenCV</span>
                            <span class="tech-badge">BeautifulSoup</span>
                        </div>
                        """)

                        gr.Markdown("""
                        ### πŸ“š Featured Projects

                        **πŸ•·οΈ Web Scraping & Classification System**
                        - Async web scraping with content classification using fine-tuned Mistral 7B
                        - Redis-based task management and progress tracking
                        - Docker containerized deployment

                        **πŸ‘οΈ Computer Vision Applications**
                        - Real-time face recognition with InsightFace
                        - RTSP camera stream processing
                        - CUDA-optimized performance

                        **🧠 LLM Fine-tuning & Deployment**
                        - Custom model training with Unsloth framework
                        - API deployment on Modal.com and Hugging Face Spaces
                        - Batch processing and inference optimization
                        """)

                    with gr.Column(scale=1):
                        gr.Markdown("""
                        ### πŸ“ž Contact Information

                        **Location:** Simferopol, Crimea  
                        **Focus:** AI/ML Engineering & Deployment  
                        **Experience:** Production systems, MLOps, Full-stack development

                        ### 🎯 Expertise Areas

                        - **Machine Learning**: Model training, fine-tuning, optimization
                        - **Computer Vision**: Face recognition, object detection, image processing
                        - **NLP**: Text classification, sentiment analysis, LLM deployment
                        - **Web Scraping**: Large-scale data extraction and processing
                        - **MLOps**: Model deployment, monitoring, CI/CD pipelines
                        - **Backend Development**: FastAPI, async programming, database design
                        """)

                        gr.HTML("""
                        <div class="project-card">
                            <h4>πŸš€ Ready to Explore?</h4>
                            <p>Navigate through the tabs above to interact with live demos of my projects. 
                            Each tab represents a different area of expertise with hands-on functionality.</p>
                        </div>
                        """)

            # Computer Vision Tab
            with gr.Tab("πŸ€– LLM"):
                gr.Markdown("""
                ## LLM Demo

                Demonstrating various computer vision capabilities including face detection, 
                object detection, and image classification. Built with OpenCV, InsightFace, 
                and custom trained models.

                ### πŸ” Available Models:
                - **Face Detection**: Locate and identify faces in images
                - **Object Detection**: Identify and classify objects
                - **Image Classification**: Categorize images into predefined classes
                """)

                # Embedding section
                gr.HTML("""
                    <iframe src="https://limitedonly41-cv-website-classify.hf.space" 
                            frameborder="0" 
                            width="100%" 
                            height="850px">
                    </iframe>
                """)



            
            # Web Scraping Tab
            with gr.Tab("πŸ•·οΈ Web Scraping & Classification"):
                gr.Markdown("""
                ## Web Scraping & Content Classification System

                This project demonstrates an advanced web scraping system that uses machine learning 
                to classify websites into categories. Built with FastAPI, Redis, and a fine-tuned 
                Mistral 7B model for accurate content classification.

                ### ✨ Key Features:
                - **Async scraping** with configurable concurrency
                - **ML-based classification** (OTHER, NEWS/BLOG, E-COMMERCE)
                - **Real-time progress tracking** with Redis
                - **Robust error handling** and retry mechanisms
                - **Export results** in JSON format
                """)

                with gr.Row():
                    with gr.Column():
                        urls_input = gr.Textbox(
                            label="URLs to Scrape (one per line)",
                            placeholder="https://example.com\nhttps://news.bbc.com\nhttps://amazon.com",
                            lines=6,
                            value="https://example.com\nhttps://news.bbc.com\nhttps://github.com\nhttps://stackoverflow.com\nhttps://amazon.com"
                        )

                        scrape_btn = gr.Button("πŸš€ Start Scraping & Classification", variant="primary")

                        with gr.Row():
                            sample_btn = gr.Button("πŸ“‹ Load Sample URLs", variant="secondary")
                            clear_btn = gr.Button("πŸ—‘οΈ Clear", variant="secondary")

                    with gr.Column():
                        status_output = gr.Textbox(label="Status", interactive=False)
                        results_output = gr.Textbox(
                            label="Classification Results", 
                            lines=10, 
                            interactive=False
                        )

                        with gr.Row():
                            json_output = gr.File(label="Download Results (JSON)")

                # Event handlers
                scrape_btn.click(
                    scraper.simulate_scraping,
                    inputs=[urls_input],
                    outputs=[results_output, status_output]
                )

                sample_btn.click(
                    lambda: "\n".join(scraper.demo_results.keys()),
                    outputs=[urls_input]
                )

                clear_btn.click(
                    lambda: ("", "", ""),
                    outputs=[urls_input, status_output]
                )

            # Computer Vision Tab
            with gr.Tab("πŸ‘οΈ Computer Vision"):
                gr.Markdown("""
                ## Computer Vision Processing Demo

                Demonstrating various computer vision capabilities including face detection, 
                object detection, and image classification. Built with OpenCV, InsightFace, 
                and custom trained models.

                ### πŸ” Available Models:
                - **Face Detection**: Locate and identify faces in images
                - **Object Detection**: Identify and classify objects
                - **Image Classification**: Categorize images into predefined classes
                """)

                with gr.Row():
                    with gr.Column():
                        image_input = gr.Image(label="Upload Image", type="pil")
                        model_dropdown = gr.Dropdown(
                            choices=["Face Detection", "Object Detection", "Image Classification"],
                            value="Face Detection",
                            label="Select Model"
                        )
                        process_btn = gr.Button("πŸ” Process Image", variant="primary")

                    with gr.Column():
                        cv_status = gr.Textbox(label="Status", interactive=False)
                        cv_results = gr.Textbox(
                            label="Analysis Results",
                            lines=8,
                            interactive=False
                        )

                process_btn.click(
                    simulate_cv_processing,
                    inputs=[image_input, model_dropdown],
                    outputs=[cv_results, cv_status]
                )

            # Text Analysis Tab
            with gr.Tab("πŸ“ Text Analysis"):
                gr.Markdown("""
                ## Natural Language Processing Demo

                Advanced text analysis capabilities including sentiment analysis, text summarization,
                and named entity recognition. Powered by transformer models and custom NLP pipelines.

                ### 🧠 Analysis Types:
                - **Sentiment Analysis**: Determine emotional tone of text
                - **Summarization**: Generate concise summaries of long text
                - **Named Entity Recognition**: Extract entities like names, places, organizations
                """)

                with gr.Row():
                    with gr.Column():
                        text_input = gr.Textbox(
                            label="Text to Analyze",
                            lines=6,
                            placeholder="Enter your text here...",
                            value="The latest developments in artificial intelligence and machine learning are revolutionizing industries across the globe. From healthcare to finance, companies are implementing AI solutions to improve efficiency and decision-making."
                        )

                        analysis_dropdown = gr.Dropdown(
                            choices=["Sentiment Analysis", "Summarization", "Named Entity Recognition"],
                            value="Sentiment Analysis",
                            label="Analysis Type"
                        )

                        analyze_btn = gr.Button("πŸ”¬ Analyze Text", variant="primary")

                    with gr.Column():
                        text_results = gr.Textbox(
                            label="Analysis Results",
                            lines=8,
                            interactive=False
                        )

                analyze_btn.click(
                    simulate_text_analysis,
                    inputs=[text_input, analysis_dropdown],
                    outputs=[text_results]
                )

            # Data Visualization Tab
            with gr.Tab("πŸ“Š Data Visualization"):
                gr.Markdown("""
                ## Interactive Data Visualization

                Create dynamic visualizations from your data using Plotly and Pandas. 
                Upload your own CSV files or explore with sample data.

                ### πŸ“ˆ Visualization Types:
                - **Line Charts**: Perfect for trends over time
                - **Bar Charts**: Great for categorical comparisons
                - **Pie Charts**: Ideal for showing proportions
                - **Scatter Plots**: Excellent for correlation analysis
                """)

                with gr.Tabs():
                    with gr.Tab("Sample Data"):
                        with gr.Row():
                            chart_type = gr.Dropdown(
                                choices=["Line Chart", "Bar Chart", "Pie Chart"],
                                value="Line Chart",
                                label="Chart Type"
                            )
                            generate_chart_btn = gr.Button("πŸ“Š Generate Chart", variant="primary")

                        sample_plot = gr.Plot(label="Visualization")

                        generate_chart_btn.click(
                            lambda chart_type: create_sample_chart(chart_type),
                            inputs=[chart_type],
                            outputs=[sample_plot]
                        )

                    with gr.Tab("Upload Your Data"):
                        with gr.Row():
                            csv_file = gr.File(label="Upload CSV File", file_types=[".csv"])
                            process_csv_btn = gr.Button("πŸ“‹ Process CSV", variant="primary")

                        csv_info = gr.Textbox(label="Dataset Information", lines=6, interactive=False)
                        csv_plot = gr.Plot(label="Data Visualization")

                        process_csv_btn.click(
                            process_uploaded_csv,
                            inputs=[csv_file],
                            outputs=[csv_info, csv_plot]
                        )

        # Load initial sample chart
        app.load(lambda: create_sample_chart("Line Chart"), outputs=[])

        return app

# Create and launch the application
if __name__ == "__main__":
    portfolio_app = create_portfolio_app()
    portfolio_app.launch(share=True, server_name="0.0.0.0", server_port=7860)