File size: 7,277 Bytes
18053f4
 
 
 
 
 
fc151e9
18053f4
 
 
fc151e9
18053f4
 
fc151e9
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
 
18053f4
fc151e9
18053f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc151e9
 
18053f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc151e9
18053f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc151e9
18053f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc151e9
 
18053f4
fc151e9
18053f4
fc151e9
18053f4
 
fc151e9
18053f4
 
 
 
 
fc151e9
18053f4
 
 
 
 
 
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
import gradio as gr
from sentence_transformers import SentenceTransformer, util

# Load semantic model
model = SentenceTransformer("all-MiniLM-L6-v2")

# Predefined AR/VR Q&A pairs
qa_pairs = {
    "What is Augmented Reality?": """Hello user!! 👋
Augmented Reality (AR) is a technology that enhances your perception of the real world by overlaying digital content—such as images, animations, or data—onto your physical environment. Unlike Virtual Reality, which immerses you in a completely digital space, AR blends the virtual and the real. AR is commonly experienced through smartphones, tablets, or specialized AR glasses like Microsoft HoloLens. It’s used in gaming, education, industrial training, and even mythological storytelling, where divine avatars can appear in your living room.""",
    
    "What is Virtual Reality?": """Hello user!! 👋
Virtual Reality (VR) is a fully immersive experience where users enter a computer-generated environment that replaces the real world. Using headsets like Oculus Quest, HTC Vive, or PlayStation VR, you can explore virtual spaces, interact with objects, and even engage in multiplayer experiences. VR is widely used in gaming, therapy, architectural visualization, and spiritual simulations—imagine meditating inside a virtual temple surrounded by ambient chants and glowing deities.""",
    
    "What is SLAM in AR?": """Hello user!! 👋
SLAM stands for Simultaneous Localization and Mapping. It allows a device to understand its position in space while building a map of the environment. This enables AR applications to place virtual objects accurately in your surroundings.""",
    
    "Explain foveated rendering in VR.": """Hello user!! 👋
Foveated rendering renders high-resolution graphics only in the area where the user is looking, reducing detail in peripheral vision. This improves frame rates and VR immersion.""",
    
    "What causes latency in VR systems?": """Hello user!! 👋
Latency is the delay between a user's action and the system's response. High latency can cause motion sickness. Optimizing rendering, tracking, and refresh rates reduces latency.""",
    
    "How does spatial mapping work in AR?": """Hello user!! 👋
Spatial mapping lets AR devices scan and understand the geometry of your physical environment, creating a 3D mesh to interact realistically with virtual objects.""",
    
    "What are haptics in VR?": """Hello user!! 👋
Haptics simulate touch sensations in VR via vibrations, force feedback, or pressure, making virtual interactions feel real.""",
    
    "What is occlusion in AR?": """Hello user!! 👋
Occlusion allows virtual objects to be blocked by real-world objects, creating depth and realism in AR.""",
    
    "What is the future of AR/VR?": """Hello user!! 👋
The future lies in mixed reality, spatial computing, and AI-driven experiences with hyper-personalized avatars and brain-computer interfaces.""",
    
    "What are digital twins in AR/VR?": """Hello user!! 👋
Digital twins are virtual replicas of real-world objects, used for simulation, monitoring, and predictive modeling in AR/VR."""
}

questions = list(qa_pairs.keys())
question_embeddings = model.encode(questions, convert_to_tensor=True)

def semantic_chatbot(user_input):
    input_embedding = model.encode(user_input, convert_to_tensor=True)
    scores = util.cos_sim(input_embedding, question_embeddings)[0]
    best_match_idx = scores.argmax().item()
    best_question = questions[best_match_idx]
    return qa_pairs[best_question]

sample_questions = [
    "What is Augmented Reality?",
    "What is Virtual Reality?",
    "What is SLAM in AR?",
    "Explain foveated rendering in VR.",
    "What causes latency in VR systems?",
    "How does spatial mapping work in AR?",
    "What are haptics in VR?",
    "What is occlusion in AR?",
    "What is the future of AR/VR?",
    "What are digital twins in AR/VR?"
]

css = """
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');

.gradio-container {
    background:
        url('https://wallpaperaccess.com/full/2669014.jpg') no-repeat center center fixed,
        url('https://static.vecteezy.com/system/resources/previews/023/381/363/large_2x/metaverse-and-virtual-reality-network-concept-using-vr-headset-on-city-background-double-exposure-generative-ai-photo.jpg') no-repeat center center fixed;
    background-size: cover, cover;
    border-radius: 12px;
    padding: 20px;
    font-family: 'Orbitron', sans-serif;
    color: #ffffff;
}

input, textarea {
    background-color: #111;
    color: #0ff;
    border: 1px solid #0ff;
    box-shadow: 0 0 10px #0ff;
}

button {
    background-color: #222;
    color: #fff;
    border: 1px solid #0ff;
    box-shadow: 0 0 10px #0ff;
}

button:hover {
    box-shadow: 0 0 15px #ff00ff;
    transform: scale(1.05);
}

/* Animated Light Box Container */
.lightbox {
    display: inline-block;
    padding: 1em 2em;
    margin-bottom: 1em;
    border-radius: 15px;
    color: black;
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    animation: glow 2.5s ease-in-out infinite alternate;
    box-shadow:
        0 0 5px rgba(0,0,0,0.5),
        0 0 15px rgba(0,0,0,0.5),
        0 0 30px rgba(0,0,0,0.4),
        0 0 40px rgba(0,0,0,0.3);
}

/* Animated Light Box Tagline */
.lightbox-tagline {
    display: inline-block;
    padding: 0.5em 1.5em;
    border-radius: 15px;
    color: black;
    font-size: 1.2em;
    font-weight: 600;
    text-align: center;
    animation: glowTag 2.5s ease-in-out infinite alternate;
    box-shadow:
        0 0 3px rgba(0,0,0,0.5),
        0 0 10px rgba(0,0,0,0.5),
        0 0 20px rgba(0,0,0,0.4);
}

/* Glow Animation */
@keyframes glow {
    from {
        box-shadow:
          0 0 5px rgba(0,0,0,0.5),
          0 0 15px rgba(0,0,0,0.5),
          0 0 30px rgba(0,0,0,0.4),
          0 0 40px rgba(0,0,0,0.3);
        color: black;
    }
    to {
        box-shadow:
          0 0 15px rgba(0,0,0,0.7),
          0 0 30px rgba(0,0,0,0.7),
          0 0 60px rgba(0,0,0,0.6),
          0 0 80px rgba(0,0,0,0.5);
        color: black;
    }
}

@keyframes glowTag {
    from {
        box-shadow:
          0 0 3px rgba(0,0,0,0.5),
          0 0 10px rgba(0,0,0,0.5),
          0 0 20px rgba(0,0,0,0.4);
        color: black;
    }
    to {
        box-shadow:
          0 0 8px rgba(0,0,0,0.6),
          0 0 25px rgba(0,0,0,0.6),
          0 0 40px rgba(0,0,0,0.5);
        color: black;
    }
}
"""

with gr.Blocks(css=css) as demo:
    # Animated header
    gr.HTML(
        '''
        <div class="lightbox">✨ VRAssist ✨</div>
        <div class="lightbox-tagline">🔹 Experience augmented answers, virtual support 🔹</div>
        '''
    )

    # Chat input/output
    user_input = gr.Textbox(label="Your Question", placeholder="e.g. What is SLAM in AR?")
    submit_btn = gr.Button("Get Answer")
    output = gr.Textbox(label="Answer", interactive=False)
    submit_btn.click(fn=semantic_chatbot, inputs=user_input, outputs=output)

    # Sample question buttons
    gr.Markdown("### 🔍 Sample Questions")
    with gr.Row():
        for q in sample_questions:
            gr.Button(q).click(fn=semantic_chatbot, inputs=gr.State(q), outputs=output)

demo.launch()