File size: 7,413 Bytes
79af5cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import random

FAQS = {
    "AIoT": {
        "What is AIoT?": "AIoT (Artificial Intelligence of Things) combines AI with IoT to enable intelligent decision-making at the edge. Anktechsol specializes in AIoT implementations for industrial applications.",
        "Benefits of AIoT?": "Real-time processing, reduced latency, lower bandwidth costs, enhanced privacy, offline capability, scalable intelligence, and predictive analytics.",
        "AIoT use cases?": "Smart manufacturing, predictive maintenance, autonomous vehicles, smart cities, healthcare monitoring, retail analytics, energy management, and industrial automation.",
        "AIoT vs traditional IoT?": "Traditional IoT collects and transmits data. AIoT adds intelligence at the edge, enabling autonomous decisions without cloud dependency.",
        "How to start with AIoT?": "Identify use case, assess edge hardware, select appropriate ML models, implement edge inference, test with real data. Anktechsol provides end-to-end AIoT consulting."
    },
    "Edge AI": {
        "What is Edge AI?": "Edge AI runs machine learning models directly on IoT devices rather than in the cloud, enabling faster responses and reduced dependency on connectivity.",
        "Best Edge AI models?": "MobileNet, EfficientNet, SqueezeNet, TinyML models, YOLO variants, and quantized neural networks optimized for resource-constrained devices.",
        "Edge AI vs Cloud AI?": "Edge: Low latency, privacy, offline operation. Cloud: More compute power, easier updates, centralized management. Hybrid approaches often work best.",
        "Edge AI hardware?": "Raspberry Pi, NVIDIA Jetson, Google Coral, Arduino, ESP32, specialized AI accelerators like Intel Movidius and Edge TPU.",
        "Model optimization for edge?": "Quantization, pruning, knowledge distillation, architecture search, and converting to TensorFlow Lite or ONNX Runtime formats."
    },
    "IoT": {
        "IoT sensors explained?": "IoT sensors collect real-world data (temperature, pressure, motion, humidity, etc.) and transmit it for analysis, monitoring, and automated action.",
        "IoT protocols?": "MQTT (messaging), CoAP (constrained devices), HTTP/HTTPS (web), LoRaWAN (long-range), Zigbee (mesh), BLE (Bluetooth Low Energy).",
        "IoT security best practices?": "End-to-end encryption, device authentication, secure boot, regular OTA updates, network segmentation, and zero-trust architecture.",
        "Industrial IoT (IIoT)?": "IIoT applies IoT to manufacturing and industrial environments for predictive maintenance, quality control, asset tracking, and process optimization.",
        "IoT data analytics?": "Collect sensor data, preprocess and clean, apply analytics (descriptive, predictive, prescriptive), visualize insights, and trigger automated actions."
    },
    "Implementation": {
        "How to deploy Edge AI models?": "Export model to edge format (TFLite/ONNX), optimize for target hardware, integrate with application code, test performance, and deploy with monitoring.",
        "Edge AI latency optimization?": "Use hardware acceleration, optimize model architecture, apply quantization, batch requests, and cache frequently used predictions.",
        "AIoT project challenges?": "Hardware constraints, model accuracy vs size tradeoffs, power management, connectivity issues, security concerns, and scalability. Anktechsol helps navigate these.",
        "Cost of AIoT implementation?": "Varies by scale: Pilot projects $10K-50K, production deployments $50K-500K+. ROI typically achieved in 6-18 months through efficiency gains.",
        "AIoT maintenance?": "Monitor device health, push OTA updates, retrain models with new data, replace aging hardware, and continuously optimize performance."
    }
}

def search_faq(query, category="All"):
    if not query or len(query) < 3:
        return "πŸ’‘ Please enter at least 3 characters to search."
    
    query = query.lower()
    results = []
    search_cats = FAQS.keys() if category == "All" else [category]
    
    for cat in search_cats:
        if cat in FAQS:
            for question, answer in FAQS[cat].items():
                if query in question.lower() or query in answer.lower():
                    results.append(f"**Category: {cat}**\n\n**Q: {question}**\n\n{answer}\n\n---\n")
    
    if results:
        return "\n".join(results[:5]) + "\n\nπŸ’‘ **Need custom AIoT solutions?** [Contact Anktechsol](https://anktechsol.com)"
    else:
        return f"❌ No results found for '{query}'.\n\nπŸ’‘ Try: 'edge ai', 'sensors', 'protocols', 'security', 'implementation'"

def get_random_faq():
    cat = random.choice(list(FAQS.keys()))
    question = random.choice(list(FAQS[cat].keys()))
    answer = FAQS[cat][question]
    return f"**Category: {cat}**\n\n**Q: {question}**\n\n{answer}\n\n---\n\nπŸ’‘ Ask your own question or search by category!"

def browse_category(category):
    if category not in FAQS:
        return "Category not found."
    
    result = f"# πŸ“š {category} FAQs\n\n"
    for question, answer in FAQS[category].items():
        result += f"**Q: {question}**\n\n{answer}\n\n---\n\n"
    result += "\nπŸ’‘ **Need expert guidance?** [Visit Anktechsol](https://anktechsol.com)"
    return result

with gr.Blocks(title="AIoT FAQ Chatbot - Anktechsol", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # πŸ’¬ AIoT & Edge AI FAQ Chatbot
    ### by **Anktechsol** - AI + IoT Experts
    
    Get instant answers about AIoT, Edge AI, IoT protocols, sensors, and industrial implementations.
    Ask questions, search topics, or browse by category!
    """)
    
    with gr.Tabs():
        with gr.Tab("πŸ” Search"):
            with gr.Row():
                with gr.Column(scale=2):
                    query_input = gr.Textbox(label="Ask your question", placeholder="e.g., What is Edge AI?")
                    category_select = gr.Dropdown(choices=["All", "AIoT", "Edge AI", "IoT", "Implementation"], value="All", label="Filter by Category")
                    search_btn = gr.Button("πŸ” Search", variant="primary", size="lg")
                    random_btn = gr.Button("🎲 Random FAQ", size="lg")
                
                with gr.Column(scale=3):
                    output = gr.Markdown()
            
            search_btn.click(fn=search_faq, inputs=[query_input, category_select], outputs=output)
            random_btn.click(fn=get_random_faq, outputs=output)
        
        with gr.Tab("πŸ“š Browse Categories"):
            gr.Markdown("### Select a category to view all FAQs")
            cat_buttons = gr.Radio(choices=list(FAQS.keys()), label="Categories", value="AIoT")
            browse_output = gr.Markdown()
            
            cat_buttons.change(fn=browse_category, inputs=cat_buttons, outputs=browse_output)
    
    gr.Markdown("""
    ---
    ### πŸ”— Resources
    - [**Anktechsol Website**](https://anktechsol.com) - Enterprise AIoT solutions
    - [**More Tools**](https://huggingface.co/anktechsol) - Free AI + IoT tools
    - **Contact us** for custom implementations and consulting
    
    ### πŸ“Š Topics Covered
    **AIoT** | **Edge AI** | **IoT Protocols** | **Security** | **Implementation**
    """)
    
    demo.load(fn=get_random_faq, outputs=output)
    demo.load(fn=lambda: browse_category("AIoT"), outputs=browse_output)

if __name__ == "__main__":
    demo.launch()