Spaces:
Sleeping
Sleeping
feat: upgrade to ENIAD Assistant interactive AI chatbot [skip ci]
Browse filesFiles changed (3)
- README.md+18-8
- app.py+135-47
- requirements.txt+2-1
12345678910111213---title: Chat Modelemoji: 💬colorFrom: yellowcolorTo: purplesdk: gradiosdk_version: 5.0.1app_file: app.pypinned: falseshort_description: Testing---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).1234567891011121314151617181920212223---title: ENIAD Assistant & Enterprise AI Chatbotemoji: 🎓colorFrom: bluecolorTo: indigosdk: gradiosdk_version: 5.9.1app_file: app.pypinned: truelicense: mitshort_description: Interactive AI Assistant fine-tuned on ENIAD academic curriculum & Enterprise ALM.---# 🎓 ENIAD Assistant — Intelligent Academic & Enterprise AI ChatbotWelcome 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.### 🧠 Model Architecture & Foundation- **Base Architecture:** LLaMA 3.1 8B Instruct- **Fine-Tuning Technique:** Parameter-Efficient Fine-Tuning (PEFT / LoRA) with 8-bit BitsAndBytes quantization- **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)- **Model Weights & LoRA Hub:** [`bosaj/eniad-llama3.1-8b-assistant-lora`](https://huggingface.co/bosaj/eniad-llama3.1-8b-assistant-lora)- **Author:** **Oussama EL HADJI** (AI & Automation Engineer @ Circet Morocco • ENIAD Graduate)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import gradio as grfrom huggingface_hub import InferenceClient"""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"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})if val[1]:messages.append({"role": "assistant", "content": val[1]})messages.append({"role": "user", "content": message})response = ""for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(minimum=0.1,maximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)",),],)if __name__ == "__main__":demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152import osimport gradio as grfrom huggingface_hub import InferenceClientPRIMARY_MODEL = "ahmed-ouka/my-llama3.1-8B-with-lora-Eniad-Assistant"FALLBACK_MODEL = "meta-llama/Meta-Llama-3.1-8B-Instruct"HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN")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).Your mission is to provide accurate, insightful guidance on:1. The National School of Artificial Intelligence and Digital (ENIAD) curriculum, engineering degree specialties, courses, and admissions.2. Enterprise AI engineering, Agentic RAG systems, and Power Automate ALM frameworks (FlowWatcher, FlowLogger).3. The bridge between mathematical physics (first-principles reasoning) and production machine learning systems.Be professional, courteous, clear, and bilingual (respond fluently in French or English according to the user's inquiry)."""def predict(message, history, model_choice, max_tokens, temperature):messages = [{"role": "system", "content": SYSTEM_PROMPT}]for h in history:messages.append({"role": "user", "content": h[0]})messages.append({"role": "assistant", "content": h[1]})messages.append({"role": "user", "content": message})client = InferenceClient(model=model_choice, token=HF_TOKEN)response_text = ""try:stream = client.chat.completions.create(messages=messages,max_tokens=max_tokens,temperature=temperature,stream=True)for chunk in stream:token = chunk.choices[0].delta.content or ""response_text += tokenyield response_textexcept Exception as e:# Fallback to standard generation or fallback modeltry:fb_client = InferenceClient(model=FALLBACK_MODEL, token=HF_TOKEN)fb_stream = fb_client.chat.completions.create(messages=messages,max_tokens=max_tokens,temperature=temperature,stream=True)for chunk in fb_stream:token = chunk.choices[0].delta.content or ""response_text += tokenyield response_textexcept Exception as fb_err:yield f"Note: Model inference endpoint warming up or requires local adapter execution. Details: {str(e)}"custom_css = """.gradio-container {max-width: 1000px !important;margin: auto !important;}.header-box {text-align: center;padding: 18px;background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);border-radius: 12px;color: white;margin-bottom: 20px;border: 1px solid #312e81;}.badge-row {display: flex;justify-content: center;gap: 8px;margin-top: 10px;}"""with gr.Blocks(css=custom_css, title="ENIAD Assistant — AI & Engineering Hub") as demo:gr.HTML("""<div class="header-box"><h1>🎓 ENIAD Assistant & Enterprise AI Hub</h1><p>Interactive Conversational Model Powered by LLaMA-3.1-8B LoRA Fine-Tuned for Moroccan AI Engineering Academia</p><div class="badge-row"><img src="https://img.shields.io/badge/ENIAD-State%20Engineer-blue?style=flat-square" /><img src="https://img.shields.io/badge/Circet%20Morocco-AI%20Automation-orange?style=flat-square" /><img src="https://img.shields.io/badge/Model-LLaMA%203.1%208B%20LoRA-purple?style=flat-square" /><img src="https://img.shields.io/badge/Author-Oussama%20EL%20HADJI-brightgreen?style=flat-square" /></div></div>""")with gr.Row():with gr.Column(scale=4):chatbot = gr.Chatbot(height=480, show_label=False)msg = gr.Textbox(placeholder="Ask about the ENIAD curriculum, course modules, Power Automate ALM, or AI engineering...",label="Your Question / Message",lines=2)with gr.Row():submit_btn = gr.Button("Send Message 🚀", variant="primary")clear_btn = gr.Button("Clear Chat 🔄")gr.Examples(examples=[["Quelles sont les compétences clés formées à l'ENIAD dans le cycle d'ingénieur en IA ?"],["Explain the architecture of the Power Automate ALM framework developed at Circet Morocco."],["How does reasoning from first principles in physics benefit production machine learning?"],["Comment le modèle LLaMA-3.1-8B a-t-il été adapté avec LoRA pour l'assistant ENIAD ?"]],inputs=msg,label="💡 Quick Prompts")with gr.Column(scale=1):gr.Markdown("### ⚙️ Model Parameters")model_selector = gr.Dropdown(choices=[PRIMARY_MODEL, FALLBACK_MODEL],value=PRIMARY_MODEL,label="Active Model Endpoint")max_tokens = gr.Slider(minimum=64, maximum=2048, value=512, step=64, label="Max Tokens")temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.05, label="Temperature")gr.Markdown("""---### 👨💻 Engineering Credits- **Author:** Oussama EL HADJI- **Role:** AI & Automation Engineer @ Circet Morocco- **Degree:** State Engineer in AI (ENIAD)- **Ecosystem:** [GitLab Profile](https://gitlab.com/Bosaj) • [GitHub Profile](https://github.com/Bosaj) • [Portfolio](https://bosaj.vercel.app)""")def user(user_message, history):return "", history + [[user_message, None]]def bot(history, model_choice, max_tokens, temperature):user_message = history[-1][0]history[-1][1] = ""for chunk in predict(user_message, history[:-1], model_choice, max_tokens, temperature):history[-1][1] = chunkyield historymsg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, [chatbot, model_selector, max_tokens, temperature], chatbot)submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, [chatbot, model_selector, max_tokens, temperature], chatbot)clear_btn.click(lambda: None, None, chatbot, queue=False)if __name__ == "__main__":demo.launch()
1huggingface_hub==0.25.212gradio>=5.9.1huggingface_hub>=0.28.0
README.md+18-8
app.py+135-47
requirements.txt+2-1