Update app.py
Browse files1234567891011121327 unmodified lines414243444546479 unmodified lines575859606162636436 unmodified lines101102103104105106107108109110111import gradio as grimport spacesfrom functools import lru_cache# Cache model loading to optimize performance@lru_cache(maxsize=3)def load_hf_model(model_name):return gr.load(name=f"deepseek-ai/{model_name}",src="huggingface",api_name="/chat")27 unmodified linesexcept Exception as e:assistant_response = f"Error: {str(e)}"history.append((input_text, assistant_response))return history, history, ""# --- Gradio Interface ---9 unmodified lineswith gr.Row():with gr.Column():# Specify type='messages' to avoid deprecation warningchatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500, type="messages")msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")with gr.Row():submit_btn = gr.Button("Submit", variant="primary")36 unmodified lines[chatbot_output, chat_history, msg])# Remove (or replace) the old `demo.fn = spaces.GPU()(demo.fn)` line# If you need GPU acceleration in Spaces, wrap demo.launch() with spaces.GPU()# as shown below. Otherwise, remove the spaces.GPU() call.if __name__ == "__main__":# Launch the Gradio app with GPU from Hugging Face Spaces# If you DON'T need GPU from `spaces`, just do: demo.launch()spaces.GPU()(demo.launch)()1234567891011121327 unmodified lines41424344454647489 unmodified lines5859606162636436 unmodified lines101102103104105import gradio as grfrom functools import lru_cache# Cache model loading to optimize performance@lru_cache(maxsize=3)def load_hf_model(model_name):# Use the Gradio-built huggingface loader instead of transformers_gradioreturn gr.load(name=f"deepseek-ai/{model_name}",src="huggingface", # Changed from transformers_gradio.registryapi_name="/chat")27 unmodified linesexcept Exception as e:assistant_response = f"Error: {str(e)}"history.append({"role": "user", "content": input_text})history.append({"role": "assistant", "content": assistant_response})return history, history, ""# --- Gradio Interface ---9 unmodified lineswith gr.Row():with gr.Column():chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500, type='messages')msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")with gr.Row():submit_btn = gr.Button("Submit", variant="primary")36 unmodified lines[chatbot_output, chat_history, msg])if __name__ == "__main__":demo.launch()
app.py+6-12