Skip to content

Commit fccfbbd

Browse files
authored
Merge pull request #41 from GYFX35/add-geometry-cartography-roles-1653576299985179350
Add geometry and cartography AI roles
2 parents aeadf97 + b082e34 commit fccfbbd

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,28 @@ def play_music_endpoint():
900900
return jsonify({"status": "success", "message": message})
901901

902902

903+
@app.route('/api/v1/assistance/geometry', methods=['POST'])
904+
@require_api_key
905+
def geometry_assistance_endpoint():
906+
data = request.get_json()
907+
prompt = data.get('prompt')
908+
if not prompt:
909+
return jsonify({"error": _("Prompt is required")}), 400
910+
message = google_ai.provide_geometry_assistance(prompt)
911+
return jsonify({"status": "success", "message": message})
912+
913+
914+
@app.route('/api/v1/assistance/cartography', methods=['POST'])
915+
@require_api_key
916+
def cartography_assistance_endpoint():
917+
data = request.get_json()
918+
prompt = data.get('prompt')
919+
if not prompt:
920+
return jsonify({"error": _("Prompt is required")}), 400
921+
message = google_ai.provide_cartography_assistance(prompt)
922+
return jsonify({"status": "success", "message": message})
923+
924+
903925
@app.route('/api/register', methods=['POST'])
904926
def register():
905927
data = request.get_json()

frontend/static/js/script.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,80 @@ document.addEventListener('DOMContentLoaded', () => {
362362
}
363363
});
364364
}
365+
366+
// --- Geometry Assistant ---
367+
const geometryAssistantBtn = document.getElementById('geometry-assistant-btn');
368+
if (geometryAssistantBtn) {
369+
geometryAssistantBtn.addEventListener('click', async () => {
370+
const input = document.getElementById('geometry-assistant-input');
371+
const responseContainer = document.getElementById('geometry-assistant-response');
372+
const apiKey = prompt("Please enter your API key to use the Geometry Assistant:");
373+
374+
if (!apiKey) {
375+
responseContainer.textContent = 'API key is required.';
376+
return;
377+
}
378+
379+
try {
380+
const response = await fetch('/api/v1/assistance/geometry', {
381+
method: 'POST',
382+
headers: {
383+
'Content-Type': 'application/json',
384+
'X-API-Key': apiKey
385+
},
386+
body: JSON.stringify({
387+
prompt: input.value
388+
})
389+
});
390+
391+
if (!response.ok) {
392+
const error = await response.json();
393+
throw new Error(error.error || 'Failed to get a response from the geometry assistant');
394+
}
395+
396+
const result = await response.json();
397+
responseContainer.textContent = result.message;
398+
} catch (error) {
399+
responseContainer.textContent = `Error: ${error.message}`;
400+
}
401+
});
402+
}
403+
404+
// --- Cartography Assistant ---
405+
const cartographyAssistantBtn = document.getElementById('cartography-assistant-btn');
406+
if (cartographyAssistantBtn) {
407+
cartographyAssistantBtn.addEventListener('click', async () => {
408+
const input = document.getElementById('cartography-assistant-input');
409+
const responseContainer = document.getElementById('cartography-assistant-response');
410+
const apiKey = prompt("Please enter your API key to use the Cartography Assistant:");
411+
412+
if (!apiKey) {
413+
responseContainer.textContent = 'API key is required.';
414+
return;
415+
}
416+
417+
try {
418+
const response = await fetch('/api/v1/assistance/cartography', {
419+
method: 'POST',
420+
headers: {
421+
'Content-Type': 'application/json',
422+
'X-API-Key': apiKey
423+
},
424+
body: JSON.stringify({
425+
prompt: input.value
426+
})
427+
});
428+
429+
if (!response.ok) {
430+
const error = await response.json();
431+
throw new Error(error.error || 'Failed to get a response from the cartography assistant');
432+
}
433+
434+
const result = await response.json();
435+
responseContainer.textContent = result.message;
436+
} catch (error) {
437+
responseContainer.textContent = `Error: ${error.message}`;
438+
}
439+
});
440+
}
365441
});

frontend/templates/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ <h3>{{ _('Music Instrumentalist Player') }}</h3>
7777
</div>
7878
</section>
7979

80+
<!-- Geometry Assistant Section -->
81+
<section id="geometry-assistant" class="services">
82+
<h2>{{ _('Geometry Assistant') }}</h2>
83+
<div class="service-cards">
84+
<div class="card">
85+
<h3>{{ _('Get help with geometry problems') }}</h3>
86+
<p>{{ _('Enter your geometry question or problem below.') }}</p>
87+
<textarea id="geometry-assistant-input" placeholder="{{ _('Your geometry question') }}" class="styled-textarea" rows="4"></textarea>
88+
<button id="geometry-assistant-btn" class="btn">{{ _('Submit') }}</button>
89+
<div class="response-container" id="geometry-assistant-response-container">
90+
<pre id="geometry-assistant-response"></pre>
91+
</div>
92+
</div>
93+
</div>
94+
</section>
95+
96+
<!-- Cartography Assistant Section -->
97+
<section id="cartography-assistant" class="services">
98+
<h2>{{ _('Cartography Assistant') }}</h2>
99+
<div class="service-cards">
100+
<div class="card">
101+
<h3>{{ _('Get help with maps and cartography') }}</h3>
102+
<p>{{ _('Enter your cartography or GIS question below.') }}</p>
103+
<textarea id="cartography-assistant-input" placeholder="{{ _('Your cartography question') }}" class="styled-textarea" rows="4"></textarea>
104+
<button id="cartography-assistant-btn" class="btn">{{ _('Submit') }}</button>
105+
<div class="response-container" id="cartography-assistant-response-container">
106+
<pre id="cartography-assistant-response"></pre>
107+
</div>
108+
</div>
109+
</div>
110+
</section>
111+
80112
<!-- Music Instrumentalist Section -->
81113
<section id="music-instrumentalist" class="services">
82114
<h2>{{ _('Music Instrumentalist Player') }}</h2>

google_ai.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,57 @@ def play_music_instrumental(prompt: str) -> str:
477477
except Exception as e:
478478
print(f"Error providing music instrumentalist assistance with Vertex AI: {e}")
479479
return f"Error: {e}"
480+
481+
482+
def provide_geometry_assistance(prompt: str) -> str:
483+
"""
484+
Provides geometry assistance using Vertex AI.
485+
"""
486+
model = GenerativeModel("gemini-1.5-flash")
487+
488+
generation_prompt = f"""
489+
You are an expert mathematician specializing in geometry. Your task is to provide clear, accurate, and helpful assistance with geometry problems, theorems, and concepts.
490+
You should be able to explain Euclidean geometry, non-Euclidean geometry, analytic geometry, and differential geometry.
491+
492+
User Request:
493+
---
494+
{prompt}
495+
---
496+
497+
Provide a professional and educational response.
498+
"""
499+
500+
try:
501+
response = model.generate_content(generation_prompt)
502+
return response.text.strip()
503+
504+
except Exception as e:
505+
print(f"Error providing geometry assistance with Vertex AI: {e}")
506+
return f"Error: {e}"
507+
508+
509+
def provide_cartography_assistance(prompt: str) -> str:
510+
"""
511+
Provides cartography assistance using Vertex AI.
512+
"""
513+
model = GenerativeModel("gemini-1.5-flash")
514+
515+
generation_prompt = f"""
516+
You are an expert cartographer and GIS specialist. Your task is to provide assistance with map making, geographical data analysis, coordinate systems, and map projections.
517+
You should be knowledgeable about both historical and modern cartographic techniques.
518+
519+
User Request:
520+
---
521+
{prompt}
522+
---
523+
524+
Provide a professional and detailed response.
525+
"""
526+
527+
try:
528+
response = model.generate_content(generation_prompt)
529+
return response.text.strip()
530+
531+
except Exception as e:
532+
print(f"Error providing cartography assistance with Vertex AI: {e}")
533+
return f"Error: {e}"

0 commit comments

Comments
 (0)