Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
# About The Hackathon
The MoroccoAI InnovAI Hackathon is a unique opportunity for AI enthusiasts, professionals, and innovators to collaborate and create transformative AI-based solutions addressing real-life challenges in Morocco and across Africa. As part of the annual MoroccoAI Annual Conference, this hackathon is set under the theme “Driving the Future of Innovation Through AI”, inspiring participants to harness AI’s capabilities to make a meaningful societal impact. Participants will join teams to develop Proof of Concepts (PoCs) using applications or APIs that address challenges in various domains. Education, Healthcare, Environment, Finance or Customer Services .

In line with MoroccoAI’s mission, this hackathon centers around “Driving the Future of Innovation Through AI”. AI has the power to redefine industries, address community needs, and propel sustainable growth. Through this event, participants will dive into AI’s potential by developing impactful solutions that address challenges unique to Morocco and Africa in fields such as agriculture, education, health, and finance, fostering innovation in response to real-world needs.

# The Challenge
Connect with the MoroccoAI community, join teams and brainstorm ideas then come up with a project that leverages AI in 5 areas of focus:
* Innovation
* Healthcare
* Environment
* Finance
* CustomerServices

# Mentorship
Join the Hackathon server on discord and meet the mentors to learn more about their proposed projects.

# Why should you participate in this Hackathon?
* Hands-on experience in AI project development that targets relevant issues in Morocco and Africa.
* Mentorship and networking opportunities with experts and peers in the AI community.
* Showcase their solutions to a jury of AI specialists at the awards ceremony, creating visibility and opportunities for further development.
* Win great prizes offered by MoroccoAI's sponsors
* Obtain your MoroccoAI certificate of recognition

# For more information
https://morocco.ai/events/conferences/MoroccoAI-Conference-2024/pages/hackathon.html
# Aabar

Aabar is a centralized web app designed to monitor and manage underground water resources. It simplifies the well drilling licensing process, ensures compliance with water regulations, and predicts water availability using advanced data analytics. The app aims to combat illegal drilling and promote sustainable water management. Its target market includes government agencies, agricultural businesses, environmental organizations, and research institutions focused on water conservation.

# Main features:
- Real-time monitoring of wells
- A LLaMa-based chatbot fine-tuned on Moroccan water laws using RAG
- A water depth predictor using Random Forest and Graph-based radius neighbors regression fact-checked by a hydro-geo engineer
- A licensor after predicting the depth at a certain point


**Tested on Ubuntu, python 3.12.4, please make sure that the libraries are well installed, make sure that scikit-learn version is 1.3.2, failing in that will cause the predictor to not work as expected, and make sure sure that the jwt library is pyjwt, using an older python causes the whole dahboard to not function and using incorrect libraries may cause issues, here is a preliminary list of requirements, any issue or incorrect results will be caused either by the API keys or/and incorrect libraries as happened in the demo in the predictor after API key reset:**

```txt
camel_tools==1.5.5
earthengine_api==1.1.2
ee==0.2
fastapi==0.115.5
gdown==5.2.0
geopy==2.4.1
nltk==3.8.2
numpy==1.24.4
pandas==2.0.3
pinecone==5.4.1
plotly==5.24.1
protobuf==5.29.0
pydantic==2.10.2
Requests==2.32.3
SQLAlchemy==2.0.30
streamlit==1.35.0
tqdm==4.66.2
```

# Initialization:
```
python3 api_setup.py
```
# How to run (landing page):

```
npm i
npm run dev
```
# How to run (streamlit dashboard):

```
uvicorn fastapi_server:app --reload
streamlit run main.py
```
Empty file added __init__.py
Empty file.
31 changes: 31 additions & 0 deletions api_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import requests

def download_json_files(url1, url2, file1_name="apis_keys.json", file2_name="morocco-ai-2024-a2fad45fa0f6.json"):
script_folder = os.path.dirname(os.path.abspath(__file__))

file1_path = os.path.join(script_folder, file1_name)
file2_path = os.path.join(script_folder, file2_name)

try:
response1 = requests.get(url1)
response1.raise_for_status() # Check for HTTP request errors
with open(file1_path, 'w', encoding='utf-8') as f:
f.write(response1.text)
print(f"File 1 downloaded and saved as {file1_name}")
except requests.RequestException as e:
print(f"Failed to download file 1: {e}")

try:
response2 = requests.get(url2)
response2.raise_for_status() # Check for HTTP request errors
with open(file2_path, 'w', encoding='utf-8') as f:
f.write(response2.text)
print(f"File 2 downloaded and saved as {file2_name}")
except requests.RequestException as e:
print(f"Failed to download file 2: {e}")

url1 = "https://link.storjshare.io/s/jvb3xajg5f5pwa7keajpaweop5bq/moroccoai/apis_keys.json?download=1"
url2 = "https://link.storjshare.io/s/jvoa25ndqo7645sbbatre66xwucq/moroccoai/morocco-ai-2024-a2fad45fa0f6.json?download=1"

download_json_files(url1, url2)
Binary file added assets/img/anzar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bins/i.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
92 changes: 92 additions & 0 deletions chatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
import requests
import json
import logging
from rag import ArabicRAG

# Configure logging
logging.basicConfig(filename='log/chatbot.log', level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

class AnzarAssistant:
def __init__(self, api_key: str, model_url: str):
self.api_key = api_key
self.model_url = model_url
logging.info("AnzarAssistant initialized with model URL: %s", model_url)

def generate_response(self, query: str, context: str) -> str:
logging.info("Generating response for query: %s", query)
prompt = f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>أنت أنزار، ملك المياه في الأساطير الأمازيغية، ومساعد ذكي للغاية. أنت تقدم إجابات دقيقة ومفيدة لأسئلة المستخدمين استنادًا إلى السياق المستخرج من القانون المغربي 36-15 المتعلق بالمياه. أنت دائمًا تجيب باللغة العربية فقط. إليك السياق ذي الصلة الذي لديك لاستفسار المستخدم :
{context}السؤال:
{query} الإجابة باللغة العربية:
<|eot_id|><|start_header_id|>assistant<|end_header_id|>"""

parameters = {
"max_new_tokens": 4096,
"temperature": 0.01,
"top_k": 50,
"top_p": 0.95,
"return_full_text": False
}

headers = {
'Authorization': f'Bearer {self.api_key}',
'Content-Type': 'application/json'
}

payload = {
"inputs": prompt,
"parameters": parameters
}

try:
response = requests.post(self.model_url, headers=headers, json=payload)
response.raise_for_status()
response_text = response.json()[0]['generated_text'].strip()
logging.info("Response generated successfully")
return response_text
except requests.RequestException as e:
logging.error("Error generating response: %s", str(e))
return f"Error generating response: {str(e)}"


class RAGPipeline:
def __init__(self, index_name='water-laws', dimension=384, model_url="https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"):
self.rag = ArabicRAG(index_name=index_name, dimension=dimension)
logging.info("RAGPipeline initialized with index name: %s and dimension: %d", index_name, dimension)

with open('apis_keys.json') as f:
data = json.load(f)
self.huggingface_api_key = data["huggingface"]["api_key"]

self.ansar_assistant = AnzarAssistant(
api_key=self.huggingface_api_key,
model_url=model_url
)

def process_query(self, query):
logging.info("Processing query: %s", query)
contexts = self.rag.retrieve_relevant_context(query, top_k=3)

if not contexts:
logging.warning("No relevant information found for query: %s", query)
return "لم يتم العثور على معلومات ذات صلة."

context_str = "\n".join([f"- {context}" for context in contexts])
formatted_query = f"السياق ذو الصلة:\n{context_str}\n\nالسؤال: {query}"

response = self.ansar_assistant.generate_response(formatted_query, context_str)

logging.info("Query processed successfully")
return response

# # Example usage
# rag_pipeline = RAGPipeline()

# query = "ما هي العقوبات المفروضة على تلوث المياه؟"
# response = rag_pipeline.process_query(query)
# print(response)

# # save the output to a file
# with open("output.txt", "w", encoding="utf-8") as f:
# f.write(response)
Loading