Spaces:
Sleeping
Sleeping
Download app.py from sobiarazzaq/AIPoweredProject: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/sobiarazzaq/AIPoweredProject/resolve/main/app.py
- Command line
-
hf download hf://spaces/sobiarazzaq/AIPoweredProject/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sobiarazzaq/AIPoweredProject/resolve/main/app.py
1.28 kB
| import os | |
| from groq import Groq | |
| import gradio as gr | |
| os.environ["GROQ_API_KEY"] = "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" | |
| client = Groq(api_key=os.environ["GROQ_API_KEY"]) | |
| MODEL_NAME = "llama-3.3-70b-versatile" | |
| def chat_with_groq(message, history): | |
| messages = [{"role": "system", "content": "You are a helpful AI assistant."}] | |
| for u, a in history: | |
| messages += [{"role": "user", "content": u}, | |
| {"role": "assistant", "content": a}] | |
| messages.append({"role": "user", "content": message}) | |
| reply = client.chat.completions.create( | |
| model=MODEL_NAME, | |
| messages=messages, | |
| temperature=0.7, | |
| max_completion_tokens=512 | |
| ).choices[0].message.content | |
| return reply | |
| with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as demo: | |
| gr.Markdown("<h1 style='text-align:center;'>🤖 Groq-Powered Chatbot</h1>") | |
| chatbot = gr.Chatbot(height=400) | |
| msg = gr.Textbox(placeholder="Type message…", show_label=False) | |
| clear = gr.Button("🧹 Clear") | |
| def user_input(m, h): | |
| r = chat_with_groq(m, h) | |
| h.append((m, r)) | |
| return "", h | |
| msg.submit(user_input, [msg, chatbot], [msg, chatbot]) | |
| clear.click(lambda: None, None, chatbot, queue=False) | |
| demo.launch() | |