Spaces:
Sleeping
Sleeping
feat: upgrade to ENIAD Assistant interactive AI chatbot [skip ci]
Browse files- README.md +18 -8
- app.py +135 -47
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
-
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ENIAD Assistant & Enterprise AI Chatbot
|
| 3 |
+
emoji: 🎓
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.9.1
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Interactive AI Assistant fine-tuned on ENIAD academic curriculum & Enterprise ALM.
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# 🎓 ENIAD Assistant — Intelligent Academic & Enterprise AI Chatbot
|
| 15 |
+
|
| 16 |
+
Welcome to the **ENIAD Assistant**, an interactive conversational system fine-tuned on the academic curriculum of the **National School of Artificial Intelligence and Digital (ENIAD)** and enterprise automation architecture.
|
| 17 |
+
|
| 18 |
+
### 🧠 Model Architecture & Foundation
|
| 19 |
+
- **Base Architecture:** LLaMA 3.1 8B Instruct
|
| 20 |
+
- **Fine-Tuning Technique:** Parameter-Efficient Fine-Tuning (PEFT / LoRA) with 8-bit BitsAndBytes quantization
|
| 21 |
+
- **Primary Model Reference:** [`ahmed-ouka/my-llama3.1-8B-with-lora-Eniad-Assistant`](https://huggingface.co/ahmed-ouka/my-llama3.1-8B-with-lora-Eniad-Assistant)
|
| 22 |
+
- **Model Weights & LoRA Hub:** [`bosaj/eniad-llama3.1-8b-assistant-lora`](https://huggingface.co/bosaj/eniad-llama3.1-8b-assistant-lora)
|
| 23 |
+
- **Author:** **Oussama EL HADJI** (AI & Automation Engineer @ Circet Morocco • ENIAD Graduate)
|
app.py
CHANGED
|
@@ -1,64 +1,152 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
""
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 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 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
PRIMARY_MODEL = "ahmed-ouka/my-llama3.1-8B-with-lora-Eniad-Assistant"
|
| 6 |
+
FALLBACK_MODEL = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 9 |
|
| 10 |
+
SYSTEM_PROMPT = """You are the ENIAD AI Assistant, a senior academic and engineering intelligence assistant designed by Oussama EL HADJI (State Engineer in AI from ENIAD, and AI & Automation Engineer at Circet Morocco).
|
| 11 |
+
Your mission is to provide accurate, insightful guidance on:
|
| 12 |
+
1. The National School of Artificial Intelligence and Digital (ENIAD) curriculum, engineering degree specialties, courses, and admissions.
|
| 13 |
+
2. Enterprise AI engineering, Agentic RAG systems, and Power Automate ALM frameworks (FlowWatcher, FlowLogger).
|
| 14 |
+
3. The bridge between mathematical physics (first-principles reasoning) and production machine learning systems.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
Be professional, courteous, clear, and bilingual (respond fluently in French or English according to the user's inquiry)."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def predict(message, history, model_choice, max_tokens, temperature):
|
| 19 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 20 |
+
for h in history:
|
| 21 |
+
messages.append({"role": "user", "content": h[0]})
|
| 22 |
+
messages.append({"role": "assistant", "content": h[1]})
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
|
| 25 |
+
client = InferenceClient(model=model_choice, token=HF_TOKEN)
|
| 26 |
+
response_text = ""
|
| 27 |
+
try:
|
| 28 |
+
stream = client.chat.completions.create(
|
| 29 |
+
messages=messages,
|
| 30 |
+
max_tokens=max_tokens,
|
| 31 |
+
temperature=temperature,
|
| 32 |
+
stream=True
|
| 33 |
+
)
|
| 34 |
+
for chunk in stream:
|
| 35 |
+
token = chunk.choices[0].delta.content or ""
|
| 36 |
+
response_text += token
|
| 37 |
+
yield response_text
|
| 38 |
+
except Exception as e:
|
| 39 |
+
# Fallback to standard generation or fallback model
|
| 40 |
+
try:
|
| 41 |
+
fb_client = InferenceClient(model=FALLBACK_MODEL, token=HF_TOKEN)
|
| 42 |
+
fb_stream = fb_client.chat.completions.create(
|
| 43 |
+
messages=messages,
|
| 44 |
+
max_tokens=max_tokens,
|
| 45 |
+
temperature=temperature,
|
| 46 |
+
stream=True
|
| 47 |
+
)
|
| 48 |
+
for chunk in fb_stream:
|
| 49 |
+
token = chunk.choices[0].delta.content or ""
|
| 50 |
+
response_text += token
|
| 51 |
+
yield response_text
|
| 52 |
+
except Exception as fb_err:
|
| 53 |
+
yield f"Note: Model inference endpoint warming up or requires local adapter execution. Details: {str(e)}"
|
| 54 |
|
| 55 |
+
custom_css = """
|
| 56 |
+
.gradio-container {
|
| 57 |
+
max-width: 1000px !important;
|
| 58 |
+
margin: auto !important;
|
| 59 |
+
}
|
| 60 |
+
.header-box {
|
| 61 |
+
text-align: center;
|
| 62 |
+
padding: 18px;
|
| 63 |
+
background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
|
| 64 |
+
border-radius: 12px;
|
| 65 |
+
color: white;
|
| 66 |
+
margin-bottom: 20px;
|
| 67 |
+
border: 1px solid #312e81;
|
| 68 |
+
}
|
| 69 |
+
.badge-row {
|
| 70 |
+
display: flex;
|
| 71 |
+
justify-content: center;
|
| 72 |
+
gap: 8px;
|
| 73 |
+
margin-top: 10px;
|
| 74 |
+
}
|
| 75 |
+
"""
|
| 76 |
|
| 77 |
+
with gr.Blocks(css=custom_css, title="ENIAD Assistant — AI & Engineering Hub") as demo:
|
| 78 |
+
gr.HTML("""
|
| 79 |
+
<div class="header-box">
|
| 80 |
+
<h1>🎓 ENIAD Assistant & Enterprise AI Hub</h1>
|
| 81 |
+
<p>Interactive Conversational Model Powered by LLaMA-3.1-8B LoRA Fine-Tuned for Moroccan AI Engineering Academia</p>
|
| 82 |
+
<div class="badge-row">
|
| 83 |
+
<img src="https://img.shields.io/badge/ENIAD-State%20Engineer-blue?style=flat-square" />
|
| 84 |
+
<img src="https://img.shields.io/badge/Circet%20Morocco-AI%20Automation-orange?style=flat-square" />
|
| 85 |
+
<img src="https://img.shields.io/badge/Model-LLaMA%203.1%208B%20LoRA-purple?style=flat-square" />
|
| 86 |
+
<img src="https://img.shields.io/badge/Author-Oussama%20EL%20HADJI-brightgreen?style=flat-square" />
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
""")
|
| 90 |
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column(scale=4):
|
| 93 |
+
chatbot = gr.Chatbot(height=480, show_label=False)
|
| 94 |
+
msg = gr.Textbox(
|
| 95 |
+
placeholder="Ask about the ENIAD curriculum, course modules, Power Automate ALM, or AI engineering...",
|
| 96 |
+
label="Your Question / Message",
|
| 97 |
+
lines=2
|
| 98 |
+
)
|
| 99 |
+
with gr.Row():
|
| 100 |
+
submit_btn = gr.Button("Send Message 🚀", variant="primary")
|
| 101 |
+
clear_btn = gr.Button("Clear Chat 🔄")
|
| 102 |
|
| 103 |
+
gr.Examples(
|
| 104 |
+
examples=[
|
| 105 |
+
["Quelles sont les compétences clés formées à l'ENIAD dans le cycle d'ingénieur en IA ?"],
|
| 106 |
+
["Explain the architecture of the Power Automate ALM framework developed at Circet Morocco."],
|
| 107 |
+
["How does reasoning from first principles in physics benefit production machine learning?"],
|
| 108 |
+
["Comment le modèle LLaMA-3.1-8B a-t-il été adapté avec LoRA pour l'assistant ENIAD ?"]
|
| 109 |
+
],
|
| 110 |
+
inputs=msg,
|
| 111 |
+
label="💡 Quick Prompts"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
with gr.Column(scale=1):
|
| 115 |
+
gr.Markdown("### ⚙️ Model Parameters")
|
| 116 |
+
model_selector = gr.Dropdown(
|
| 117 |
+
choices=[PRIMARY_MODEL, FALLBACK_MODEL],
|
| 118 |
+
value=PRIMARY_MODEL,
|
| 119 |
+
label="Active Model Endpoint"
|
| 120 |
+
)
|
| 121 |
+
max_tokens = gr.Slider(minimum=64, maximum=2048, value=512, step=64, label="Max Tokens")
|
| 122 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.05, label="Temperature")
|
| 123 |
+
|
| 124 |
+
gr.Markdown("""
|
| 125 |
+
---
|
| 126 |
+
### 👨💻 Engineering Credits
|
| 127 |
+
- **Author:** Oussama EL HADJI
|
| 128 |
+
- **Role:** AI & Automation Engineer @ Circet Morocco
|
| 129 |
+
- **Degree:** State Engineer in AI (ENIAD)
|
| 130 |
+
- **Ecosystem:** [GitLab Profile](https://gitlab.com/Bosaj) • [GitHub Profile](https://github.com/Bosaj) • [Portfolio](https://bosaj.vercel.app)
|
| 131 |
+
""")
|
| 132 |
+
|
| 133 |
+
def user(user_message, history):
|
| 134 |
+
return "", history + [[user_message, None]]
|
| 135 |
+
|
| 136 |
+
def bot(history, model_choice, max_tokens, temperature):
|
| 137 |
+
user_message = history[-1][0]
|
| 138 |
+
history[-1][1] = ""
|
| 139 |
+
for chunk in predict(user_message, history[:-1], model_choice, max_tokens, temperature):
|
| 140 |
+
history[-1][1] = chunk
|
| 141 |
+
yield history
|
| 142 |
|
| 143 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 144 |
+
bot, [chatbot, model_selector, max_tokens, temperature], chatbot
|
| 145 |
+
)
|
| 146 |
+
submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 147 |
+
bot, [chatbot, model_selector, max_tokens, temperature], chatbot
|
| 148 |
+
)
|
| 149 |
+
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
|
|
|
|
|
|
| 1 |
+
gradio>=5.9.1
|
| 2 |
+
huggingface_hub>=0.28.0
|