Update app.py
Browse files5 unmodified lines678991011111213146 unmodified lines21222324242526272728293031323334353637293031323334353637384041424344394041424344454647474848495051525 unmodified linesdef load_hf_model(model_name): # Use the Gradio-built huggingface loader instead of transformers_gradio return gr.load( name=f"huggingface/deepseek-ai/{model_name}", name=f"deepseek-ai/{model_name}", src="huggingface", # Changed from transformers_gradio.registry api_name="chat", api_name="/chat" )
# Load all models at startup6 unmodified lines# --- Chatbot function ---def chatbot(input_text, history, model_choice, system_message, max_new_tokens, temperature, top_p): history = history or []
# Get the selected model component model_component = MODELS[model_choice]
# Create payload for the model payload = [ history, # Pass the entire history input_text, system_message, max_new_tokens, temperature, top_p ]
payload = { "messages": [{"role": "user", "content": input_text}], "system": system_message, "max_tokens": max_new_tokens, "temperature": temperature, "top_p": top_p } # Run inference using the selected model try: response = model_component(payload) # the response now it is a tuple containing the updated history as the first element and the generated text as the second updated_history, assistant_response = response[0], response[1]
history = updated_history
response = model_component(payload) # The response is likely a dictionary if isinstance(response, dict) and "choices" in response: assistant_response = response["choices"][0]["message"]["content"] else: assistant_response = "Unexpected model response format." except Exception as e: assistant_response = f"Error: {str(e)}" # Append user and assistant messages to history history.append((input_text, assistant_response))
history.append((input_text, assistant_response)) return history, history, ""
# --- Gradio Interface ---app.py+21-20