Update app.py
Browse files5 unmodified lines678910111213146 unmodified lines212223242526272829303132333435363738394041424344454647484950515 unmodified linesdef load_hf_model(model_name):# Use the Gradio-built huggingface loader instead of transformers_gradioreturn gr.load(name=f"huggingface/deepseek-ai/{model_name}",src="huggingface", # Changed from transformers_gradio.registryapi_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 componentmodel_component = MODELS[model_choice]# Create payload for the modelpayload = [history, # Pass the entire historyinput_text,system_message,max_new_tokens,temperature,top_p]# Run inference using the selected modeltry: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 secondupdated_history, assistant_response = response[0], response[1]history = updated_historyexcept Exception as e:assistant_response = f"Error: {str(e)}"history.append((input_text, assistant_response))return history, history, ""# --- Gradio Interface ---5 unmodified lines678910111213146 unmodified lines21222324252627282930313233343536373839404142434445464748495051525 unmodified linesdef 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")# 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 componentmodel_component = MODELS[model_choice]# Create payload for the modelpayload = {"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 modeltry:response = model_component(payload) # The response is likely a dictionaryif 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 historyhistory.append((input_text, assistant_response))return history, history, ""# --- Gradio Interface ---
app.py+21-20