Spaces:
Sleeping
Sleeping
Commit ·
cb4656b
1
Parent(s): fc33bcb
placed1
Browse files9 unmodified lines101112131415161738 unmodified lines565758596061626364656667686970717273747527 unmodified lines1031041051061071081099 unmodified lines# -----------------------------# Load API key from Hugging Face Secrets# -----------------------------OPENAI_KEY = os.getenv("OPENAI_API_KEY")OPENAI_URL = "https://api.openai.com/v1/chat/completions"# -----------------------------# Load TFLite model from Hugging Face Hub38 unmodified lines# -----------------------------# OpenAI Chatbot (single-turn, no history)# -----------------------------def openai_chatbot(user_message):payload = {"model": "gpt-4o-mini", # ✅ lightweight, works in Spaces"messages": [{"role": "user", "content": user_message}],"temperature": 0.7,"max_tokens": 500}headers = {"Authorization": f"Bearer {OPENAI_KEY}","Content-Type": "application/json"}response = requests.post(OPENAI_URL, headers=headers, json=payload)if response.status_code == 200:bot_message = response.json()["choices"][0]["message"]["content"]27 unmodified linesresponse_box = gr.Textbox(label="Bot Response", lines=5)send_btn = gr.Button("Send")send_btn.click(openai_chatbot, inputs=msg, outputs=response_box)if __name__ == "__main__":demo.launch()9 unmodified lines101112131415161738 unmodified lines565758596061626364656667686970717273747527 unmodified lines1031041051061071081099 unmodified lines# -----------------------------# Load API key from Hugging Face Secrets# -----------------------------GROK_KEY = os.getenv("GROK_API_KEY")GROK_URL = "https://api.groq.com/openai/v1/chat/completions"# -----------------------------# Load TFLite model from Hugging Face Hub38 unmodified lines# -----------------------------# OpenAI Chatbot (single-turn, no history)# -----------------------------def grok_chatbot(user_message):payload = {"model": "openai/gpt-oss-20b", # ✅ lightweight, works in Spaces"messages": [{"role": "user", "content": user_message}],"temperature": 0.7,"max_tokens": 500}headers = {"Authorization": f"Bearer {GROK_KEY}","Content-Type": "application/json"}response = requests.post(GROK_URL, headers=headers, json=payload)if response.status_code == 200:bot_message = response.json()["choices"][0]["message"]["content"]27 unmodified linesresponse_box = gr.Textbox(label="Bot Response", lines=5)send_btn = gr.Button("Send")send_btn.click(grok_chatbot, inputs=msg, outputs=response_box)if __name__ == "__main__":demo.launch()
app.py+7-7