import gradio as gr from groq import Groq import os # Replace with your Groq API Key (or use HF Secrets on Spaces) GROQ_API_KEY = os.getenv("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") client = Groq(api_key=GROQ_API_KEY) MODEL = "llama3-8b-8192" chat_history = [] def chat(user_input, history): chat_history.append({"role": "user", "content": user_input}) response = client.chat.completions.create( model=MODEL, messages=chat_history, temperature=0.7 ) reply = response.choices[0].message.content chat_history.append({"role": "assistant", "content": reply}) history.append((user_input, reply)) return "", history def clear_chat(): global chat_history chat_history = [] return [], "" with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("