import gradio as gr from groq import Groq import os # Load Groq API key from environment client = Groq(api_key=os.environ.get("GROQ_API_KEY")) def chat_with_mujahid_gpt(history, message): messages = [{"role": "system", "content": "You are Mujahid GPT, a helpful AI assistant."}] for user, bot in history: messages.append({"role": "user", "content": user}) messages.append({"role": "assistant", "content": bot}) messages.append({"role": "user", "content": message}) chat_completion = client.chat.completions.create( messages=messages, model="llama-3.1-8b-instant" # ✅ supported Groq model ) reply = chat_completion.choices[0].message.content history.append((message, reply)) return history, "" with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """ # 🖤 Mujahid GPT Powered by The Najafi Group CEO & Founder: *Mujahid Hussain* """) chatbot = gr.Chatbot(height=500) msg = gr.Textbox(label="Type your message...") clear = gr.Button("Clear Chat") state = gr.State([]) def user(user_message, history): return "", history + [[user_message, None]] msg.submit(user, [msg, state], [msg, state], queue=False).then( chat_with_mujahid_gpt, [state, msg], [chatbot, msg] ) clear.click(lambda: ([], ""), None, [chatbot, msg]) demo.launch()