bosaj commited on
Commit
35bc14a
·
1 Parent(s): d1b4e4e

feat: upgrade to ENIAD Assistant interactive AI chatbot [skip ci]

Browse files
Files changed (3) hide show
  1. README.md +18 -8
  2. app.py +135 -47
  3. requirements.txt +2 -1
README.md CHANGED
@@ -1,13 +1,23 @@
1
  ---
2
- title: Chat Model
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.0.1
8
  app_file: app.py
9
- pinned: false
10
- short_description: Testing
 
11
  ---
12
 
13
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
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
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
 
20
- for val in history:
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
- response = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- response += token
40
- yield response
 
 
 
 
 
 
 
 
 
 
 
41
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
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
- huggingface_hub==0.25.2
 
 
1
+ gradio>=5.9.1
2
+ huggingface_hub>=0.28.0