Update app.py
Browse files1223456789101011121327 unmodified lines4142434444454647489 unmodified lines58596060616162636436 unmodified lines101102103104105106107104109110111105import gradio as grimport spacesfrom 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_gradio return gr.load( name=f"deepseek-ai/{model_name}", src="huggingface", src="huggingface", # Changed from transformers_gradio.registry api_name="/chat" )
27 unmodified lines except Exception as e: assistant_response = f"Error: {str(e)}" history.append((input_text, assistant_response)) history.append({"role": "user", "content": input_text}) history.append({"role": "assistant", "content": assistant_response}) return history, history, ""
# --- Gradio Interface ---9 unmodified lines
with gr.Row(): with gr.Column(): # Specify type='messages' to avoid deprecation warning chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500, type="messages") 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] )
# 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)() demo.launch()app.py+6-12