Spaces:
Runtime error
Runtime error
Update app.py
Browse files123import gradio as grgr.load("models/meta-llama/Meta-Llama-3.1-70B-Instruct").launch()12345678910111213141516171819202122232425262728293031323334353637383940414243import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch# Load model and tokenizer from Hugging Face Model Hubmodel_name = "meta-llama/Meta-Llama-3.1-70B-Instruct"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)# Define system instructionsystem_instruction = "You are a helpful assistant. Provide detailed and accurate responses to the user's queries."# Define the chat functiondef chat_function(prompt):# Create the full input prompt including the system instructionfull_prompt = f"{system_instruction}\nUser: {prompt}\nAssistant:"# Tokenize the full promptinputs = tokenizer(full_prompt, return_tensors="pt")# Generate model responsewith torch.no_grad():outputs = model.generate(**inputs, max_length=150, num_return_sequences=1)# Decode and return responseresponse = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()# Extract only the assistant's responseresponse = response.split("Assistant:")[-1].strip()return response# Create Gradio interfaceiface = gr.Interface(fn=chat_function,inputs="text",outputs="text",title="Meta-Llama Chatbot",description="A chatbot powered by the Meta-Llama-3.1-70B-Instruct model.")# Launch the interfaceif __name__ == "__main__":iface.launch()
app.py+41-1