Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from sentence_transformers import SentenceTransformer, util
|
3 |
+
|
4 |
+
# Load semantic model
|
5 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
6 |
+
|
7 |
+
# Predefined AR/VR Q&A pairs with longer answers
|
8 |
+
qa_pairs = {
|
9 |
+
"What is Augmented Reality?": """Hello user!! 👋
|
10 |
+
|
11 |
+
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.""",
|
12 |
+
|
13 |
+
"What is Virtual Reality?": """Hello user!! 👋
|
14 |
+
|
15 |
+
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.""",
|
16 |
+
|
17 |
+
"What is SLAM in AR?": """Hello user!! 👋
|
18 |
+
|
19 |
+
SLAM stands for Simultaneous Localization and Mapping. It’s a core technique in AR that allows a device to understand its position in space while simultaneously building a map of the environment. This enables AR applications to place virtual objects accurately in your surroundings, even as you move. SLAM is essential for mobile AR, robotics, and autonomous navigation.""",
|
20 |
+
|
21 |
+
"Explain foveated rendering in VR.": """Hello user!! 👋
|
22 |
+
|
23 |
+
Foveated rendering is a performance optimization technique used in VR. It renders high-resolution graphics only in the area where the user is looking (the fovea), while reducing detail in peripheral vision. This reduces GPU load and improves frame rates, making VR experiences smoother and more immersive. It often works in tandem with eye-tracking hardware.""",
|
24 |
+
|
25 |
+
"What causes latency in VR systems?": """Hello user!! 👋
|
26 |
+
|
27 |
+
Latency in VR refers to the delay between a user's action (like moving their head) and the system's response (updating the display). High latency can cause motion sickness and break immersion. It’s influenced by factors like rendering speed, tracking accuracy, and display refresh rates. Optimizing latency is critical for creating comfortable and responsive VR experiences.""",
|
28 |
+
|
29 |
+
"How does spatial mapping work in AR?": """Hello user!! 👋
|
30 |
+
|
31 |
+
Spatial mapping allows AR devices to scan and understand the geometry of your physical environment. Using depth sensors or cameras, the system creates a 3D mesh of surfaces like walls, floors, and furniture. This enables virtual objects to interact realistically with the real world—like placing a divine avatar on your desk or having it walk across your floor.""",
|
32 |
+
|
33 |
+
"What are haptics in VR?": """Hello user!! 👋
|
34 |
+
|
35 |
+
Haptics refer to tactile feedback technologies that simulate touch sensations in VR. Through vibrations, force feedback, or pressure, haptics make virtual interactions feel real—like the sensation of drawing a bowstring or touching a glowing relic. Advanced haptic gloves and suits are being developed to deepen immersion in gaming, training, and storytelling.""",
|
36 |
+
|
37 |
+
"What is occlusion in AR?": """Hello user!! 👋
|
38 |
+
|
39 |
+
Occlusion in AR is the ability for virtual objects to be blocked or hidden by real-world objects. For example, if a virtual deity walks behind a real chair, it should disappear from view. This creates a sense of depth and realism. Occlusion requires accurate spatial mapping and depth sensing to work effectively.""",
|
40 |
+
|
41 |
+
"What is the future of AR/VR?": """Hello user!! 👋
|
42 |
+
|
43 |
+
The future of AR/VR lies in mixed reality, spatial computing, and AI-driven experiences. Expect seamless blending of physical and digital worlds, hyper-personalized avatars, and brain-computer interfaces that respond to thought. Myth-tech storytelling will evolve into immersive temples, divine simulations, and interactive wisdom-sharing across cultures.""",
|
44 |
+
|
45 |
+
"What are digital twins in AR/VR?": """Hello user!! 👋
|
46 |
+
|
47 |
+
Digital twins are virtual replicas of real-world objects, systems, or environments. In AR/VR, they’re used for simulation, monitoring, and predictive modeling. For example, a digital twin of a temple could be explored in VR, while its real counterpart is preserved. They’re widely used in manufacturing, smart cities, and cultural preservation.""",
|
48 |
+
}
|
49 |
+
|
50 |
+
questions = list(qa_pairs.keys())
|
51 |
+
question_embeddings = model.encode(questions, convert_to_tensor=True)
|
52 |
+
|
53 |
+
def semantic_chatbot(user_input):
|
54 |
+
input_embedding = model.encode(user_input, convert_to_tensor=True)
|
55 |
+
scores = util.cos_sim(input_embedding, question_embeddings)[0]
|
56 |
+
best_match_idx = scores.argmax().item()
|
57 |
+
best_question = questions[best_match_idx]
|
58 |
+
return qa_pairs[best_question]
|
59 |
+
|
60 |
+
sample_questions = [
|
61 |
+
"What is Augmented Reality?",
|
62 |
+
"What is Virtual Reality?",
|
63 |
+
"What is SLAM in AR?",
|
64 |
+
"Explain foveated rendering in VR.",
|
65 |
+
"What causes latency in VR systems?",
|
66 |
+
"How does spatial mapping work in AR?",
|
67 |
+
"What are haptics in VR?",
|
68 |
+
"What is occlusion in AR?",
|
69 |
+
"What is the future of AR/VR?",
|
70 |
+
"What are digital twins in AR/VR?"
|
71 |
+
]
|
72 |
+
|
73 |
+
css = """
|
74 |
+
.gradio-container {
|
75 |
+
background:
|
76 |
+
url('https://wallpaperaccess.com/full/2669014.jpg') no-repeat center center fixed,
|
77 |
+
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;
|
78 |
+
background-size: cover, cover;
|
79 |
+
border-radius: 12px;
|
80 |
+
padding: 20px;
|
81 |
+
box-shadow: 0 0 25px #00ffff;
|
82 |
+
font-family: 'Orbitron', sans-serif;
|
83 |
+
color: #ffffff;
|
84 |
+
}
|
85 |
+
|
86 |
+
input, textarea {
|
87 |
+
background-color: #111;
|
88 |
+
color: #0ff;
|
89 |
+
border: 1px solid #0ff;
|
90 |
+
box-shadow: 0 0 10px #0ff;
|
91 |
+
}
|
92 |
+
|
93 |
+
button {
|
94 |
+
background-color: #222;
|
95 |
+
color: #fff;
|
96 |
+
border: 1px solid #0ff;
|
97 |
+
box-shadow: 0 0 10px #0ff;
|
98 |
+
}
|
99 |
+
|
100 |
+
button:hover {
|
101 |
+
box-shadow: 0 0 15px #ff00ff;
|
102 |
+
transform: scale(1.05);
|
103 |
+
}
|
104 |
+
|
105 |
+
/* Animated Light Box Container */
|
106 |
+
.lightbox {
|
107 |
+
display: inline-block;
|
108 |
+
padding: 1em 2em;
|
109 |
+
margin-bottom: 1em;
|
110 |
+
border-radius: 15px;
|
111 |
+
color: black; /* Changed text color to black */
|
112 |
+
font-size: 2em;
|
113 |
+
font-weight: bold;
|
114 |
+
text-align: center;
|
115 |
+
position: relative;
|
116 |
+
animation: glow 2.5s ease-in-out infinite alternate;
|
117 |
+
box-shadow:
|
118 |
+
0 0 5px rgba(0,0,0,0.5),
|
119 |
+
0 0 15px rgba(0,0,0,0.5),
|
120 |
+
0 0 30px rgba(0,0,0,0.4),
|
121 |
+
0 0 40px rgba(0,0,0,0.3);
|
122 |
+
}
|
123 |
+
|
124 |
+
/* Animated Light Box Tagline */
|
125 |
+
.lightbox-tagline {
|
126 |
+
display: inline-block;
|
127 |
+
padding: 0.5em 1.5em;
|
128 |
+
border-radius: 15px;
|
129 |
+
color: black; /* Changed text color to black */
|
130 |
+
font-size: 1.2em;
|
131 |
+
font-weight: 600;
|
132 |
+
text-align: center;
|
133 |
+
position: relative;
|
134 |
+
animation: glowTag 2.5s ease-in-out infinite alternate;
|
135 |
+
box-shadow:
|
136 |
+
0 0 3px rgba(0,0,0,0.5),
|
137 |
+
0 0 10px rgba(0,0,0,0.5),
|
138 |
+
0 0 20px rgba(0,0,0,0.4);
|
139 |
+
}
|
140 |
+
|
141 |
+
/* Glow Animation */
|
142 |
+
@keyframes glow {
|
143 |
+
from {
|
144 |
+
box-shadow:
|
145 |
+
0 0 5px rgba(0,0,0,0.5),
|
146 |
+
0 0 15px rgba(0,0,0,0.5),
|
147 |
+
0 0 30px rgba(0,0,0,0.4),
|
148 |
+
0 0 40px rgba(0,0,0,0.3);
|
149 |
+
color: black;
|
150 |
+
}
|
151 |
+
to {
|
152 |
+
box-shadow:
|
153 |
+
0 0 15px rgba(0,0,0,0.7),
|
154 |
+
0 0 30px rgba(0,0,0,0.7),
|
155 |
+
0 0 60px rgba(0,0,0,0.6),
|
156 |
+
0 0 80px rgba(0,0,0,0.5);
|
157 |
+
color: black;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
@keyframes glowTag {
|
162 |
+
from {
|
163 |
+
box-shadow:
|
164 |
+
0 0 3px rgba(0,0,0,0.5),
|
165 |
+
0 0 10px rgba(0,0,0,0.5),
|
166 |
+
0 0 20px rgba(0,0,0,0.4);
|
167 |
+
color: black;
|
168 |
+
}
|
169 |
+
to {
|
170 |
+
box-shadow:
|
171 |
+
0 0 8px rgba(0,0,0,0.6),
|
172 |
+
0 0 25px rgba(0,0,0,0.6),
|
173 |
+
0 0 40px rgba(0,0,0,0.5);
|
174 |
+
color: black;
|
175 |
+
}
|
176 |
+
}
|
177 |
+
"""
|
178 |
+
|
179 |
+
with gr.Blocks(css=css) as demo:
|
180 |
+
gr.Markdown(
|
181 |
+
'''
|
182 |
+
<div class="lightbox">✨ VRAssist ✨</div><br>
|
183 |
+
<div class="lightbox-tagline">🔹 Experience augmented answers, virtual support 🔹</div>
|
184 |
+
''',
|
185 |
+
elem_id="animated-text",
|
186 |
+
visible=True
|
187 |
+
)
|
188 |
+
|
189 |
+
user_input = gr.Textbox(label="Your Question", placeholder="e.g. What is SLAM in AR?")
|
190 |
+
submit_btn = gr.Button("Get Answer")
|
191 |
+
output = gr.Textbox(label="Answer", interactive=False)
|
192 |
+
|
193 |
+
submit_btn.click(fn=semantic_chatbot, inputs=user_input, outputs=output)
|
194 |
+
|
195 |
+
gr.Markdown("### 🔍 Sample Questions")
|
196 |
+
with gr.Row():
|
197 |
+
for q in sample_questions:
|
198 |
+
gr.Button(q).click(fn=semantic_chatbot, inputs=gr.State(q), outputs=output)
|
199 |
+
|
200 |
+
demo.launch()
|