Update app.py
Browse files4 unmodified lines56789101112131443 unmodified lines5859606162636436 unmodified lines1011021031041051061071081091104 unmodified lines# 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")43 unmodified lineswith gr.Row():with gr.Column():chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500)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])# Add GPU support for Hugging Face Spacesdemo.fn = spaces.GPU()(demo.fn)for fn in demo.fns.values():fn.api_name = Falseif __name__ == "__main__":demo.launch()4 unmodified lines567891011121343 unmodified lines575859606162636436 unmodified lines1011021031041051061071081091101114 unmodified lines# 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")43 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)()
app.py+9-8