File size: 4,058 Bytes
115a243
 
6155801
 
 
115a243
 
 
 
 
 
6155801
115a243
 
6155801
115a243
 
 
 
 
 
 
 
6155801
 
115a243
6155801
 
 
 
 
 
 
 
 
 
 
115a243
6155801
 
115a243
6155801
 
115a243
 
 
6155801
115a243
6155801
 
115a243
6155801
 
 
115a243
6155801
 
115a243
 
6155801
 
115a243
6155801
115a243
6155801
115a243
 
 
 
 
 
 
 
6155801
115a243
6155801
115a243
6155801
115a243
 
6155801
 
115a243
6155801
 
 
 
 
 
 
115a243
6155801
115a243
 
 
6155801
 
 
 
 
 
 
 
115a243
6155801
 
115a243
6155801
115a243
 
6155801
 
 
 
 
 
 
 
115a243
6155801
 
 
115a243
 
 
 
 
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
#!/usr/bin/env python3
"""
FTTH Chatbot – Fiber Optic Engineering Demonstration
Web interface with Gradio + Llama 3.3 Instruct via NVIDIA API
Optimized for RTX 5090
"""

import gradio as gr
import os
from openai import OpenAI

# NVIDIA API configuration
NVIDIA_API_KEY = os.environ.get("NVIDIA_API_KEY")

# Initialize OpenAI client with NVIDIA endpoint
if NVIDIA_API_KEY:
    client = OpenAI(
        base_url="https://integrate.api.nvidia.com/v1",
        api_key=NVIDIA_API_KEY
    )
else:
    client = None

# System prompt for the FTTH chatbot
SYSTEM_PROMPT = """You are an expert in FTTH (Fiber to the Home) engineering – Fiber Optics to the Home.

Your role is to answer questions about:
- FTTH project design and implementation
- Fiber optic infrastructure
- Fiber access technologies
- Benefits and characteristics of FTTH
- Technical challenges and solutions
- Standards and regulations
- Costs and economic feasibility
- Comparison with other technologies (ADSL, VDSL, 4G/5G)
- Installation and maintenance of FTTH networks
- Network components (OLT, ONT, splitters, cables, etc.)

Respond in a clear, professional, and educational manner, adapting the level of technical detail to the question.
When appropriate, provide practical examples and engineering recommendations.

Keep responses concise but informative, suitable for a professional presentation.
"""

def chat_ftth_nvidia(message: str, history: list) -> str:
    """
    Function that processes FTTH-related messages using Llama 3.3 Instruct via NVIDIA API
    """

    # Check if the client is initialized
    if not client:
        return "❌ Error: NVIDIA_API_KEY is not configured. Please set it in the Space settings."

    # Build message history for the API
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]

    # Add conversation history
    for msg in history:
        messages.append(msg)

    # Add current user message
    messages.append({"role": "user", "content": message})

    try:
        # Call NVIDIA API using OpenAI client
        completion = client.chat.completions.create(
            model="meta/llama-3.3-70b-instruct",
            messages=messages,
            temperature=0.7,
            top_p=0.7,
            max_tokens=1024,
            stream=False
        )

        return completion.choices[0].message.content

    except Exception as e:
        return f"❌ Error while processing your question: {str(e)}"


# Create Gradio interface
with gr.Blocks(title="FTTH Chatbot") as demo:
    gr.Markdown("""
    # 🌐 FTTH Chatbot – Fiber Optic Engineering

    Welcome to the specialized assistant for **FTTH (Fiber to the Home)**.

    Ask questions about fiber optic projects, infrastructure, technologies, and deployment.

    **Technology:** Llama 3.3 Instruct (NVIDIA API) + RTX 5090
    """)

    chatbot = gr.ChatInterface(
        chat_ftth_nvidia,
        examples=[
            "What is FTTH and what are its main benefits?",
            "What is the difference between FTTH, FTTP, and FTTC?",
            "What are the main components of an FTTH network?",
            "How is fiber optic installation done in a residential building?",
            "What is the typical speed of an FTTH connection?",
            "What are the challenges of deploying FTTH in rural areas?",
            "How does an optical splitter work in an FTTH network?",
            "What is the approximate cost of FTTH deployment per kilometer?",
        ],
        title="FTTH Assistant",
        description="Ask your questions about FTTH and receive expert answers.",
    )

    gr.Markdown("""
    ---

    **Usage tips:**
    - Ask specific questions about FTTH technical aspects
    - Use practical examples to get more detailed answers
    - The chatbot keeps conversation context for more relevant responses

    **Technology stack:**
    - Model: Llama 3.3 Instruct (Meta)
    - API: NVIDIA Cloud
    - GPU: RTX 5090 (optimized)

    *Developed for engineering meeting demonstrations*
    """)


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