Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456723456789103 unmodified lines1415161819202122232425262728293031323317181920212223242526272829303132363733343536373839403940414242434443444510 unmodified lines56575861596360import 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")from 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 lines temperature, 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, # Construct the prompt prompt = 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 response inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate( inputs.input_ids, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p, ): token = message.choices[0].delta.content do_sample=True )
# Decode the generated response response = tokenizer.decode(outputs[0], skip_special_tokens=True)
response += token yield response # Extract the assistant's reply assistant_reply = response.split("Assistant:")[-1].strip() yield assistant_reply
"""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() demo.launch()app.py+28-31