Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910113 unmodified lines15161718192021222324252627282930313233343536373839404142434445464710 unmodified lines585960616263import gradio as grfrom huggingface_hub import InferenceClient"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("Aksh1t/mistral-7b-oig-unsloth-merged")def respond(message,3 unmodified linestemperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})if val[1]:messages.append({"role": "assistant", "content": val[1]})messages.append({"role": "user", "content": message})response = ""for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[10 unmodified lines],)if __name__ == "__main__":demo.launch()123456789103 unmodified lines141516171819202122232425262728293031323334353637383940414243444510 unmodified lines5657585960import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizer# Load the tokenizer and modelmodel_name = "Aksh1t/mistral-7b-oig-unsloth-merged"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")def respond(message,3 unmodified linestemperature,top_p,):# Construct the promptprompt = system_message + "\n"for user_msg, assistant_msg in history:if user_msg:prompt += f"User: {user_msg}\n"if assistant_msg:prompt += f"Assistant: {assistant_msg}\n"prompt += f"User: {message}\nAssistant:"# Encode the prompt and generate a responseinputs = tokenizer(prompt, return_tensors="pt")outputs = model.generate(inputs.input_ids,max_new_tokens=max_tokens,temperature=temperature,top_p=top_p,do_sample=True)# Decode the generated responseresponse = tokenizer.decode(outputs[0], skip_special_tokens=True)# Extract the assistant's replyassistant_reply = response.split("Assistant:")[-1].strip()yield assistant_replydemo = gr.ChatInterface(respond,additional_inputs=[10 unmodified lines],)if __name__ == "__main__":demo.launch()
app.py+28-31