import gradio as gr import requests import os API_KEY = os.getenv("100d2c15370546965c6fb5ea7ae2ee3c9d6e4cb5a9f36726ac771fddd4eef9a3") # Secure method! def chat_with_deepseek(user_input, history): messages = [{"role": "system", "content": "You are 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": user_input}) response = requests.post( "https://api.deepseek.com/v1/chat/completions", headers={ "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" }, json={ "model": "deepseek-chat", "messages": messages, "temperature": 0.7 } ) if response.status_code != 200: return history + [(user_input, f"Error {response.status_code}: {response.text}")], history reply = response.json()["choices"][0]["message"]["content"] history.append((user_input, reply)) return history, history with gr.Blocks() as demo: chatbot = gr.Chatbot(label="Europa", type="messages") msg = gr.Textbox(placeholder="Type your question…", show_label=False) state = gr.State([]) msg.submit(chat_with_deepseek, inputs=[msg, state], outputs=[chatbot, state]) demo.launch()