import os import gradio as gr from groq import Groq # ============================== # SET YOUR GROQ API KEY # ============================== # In Hugging Face: # Go to Settings → Secrets → Add new secret # Name: GROQ_API_KEY # Value: your_api_key_here client = Groq( api_key=os.environ.get("Keypass") ) # ============================== # CHAT FUNCTION # ============================== def chatbot_response(message, history): try: messages = [] # Add chat history for human, assistant in history: messages.append({"role": "user", "content": human}) messages.append({"role": "assistant", "content": assistant}) # Add current message messages.append({"role": "user", "content": message}) completion = client.chat.completions.create( model="llama3-70b-8192", messages=messages, temperature=0.7, max_tokens=1024, ) response = completion.choices[0].message.content return response except Exception as e: return f"Error: {str(e)}" # ============================== # GRADIO INTERFACE # ============================== demo = gr.ChatInterface( fn=chatbot_response, title="🚀 Groq AI Chatbot", description="Chatbot powered by Groq API + LLaMA3", theme="soft" ) if __name__ == "__main__": demo.launch()