Spaces:
Runtime error
Runtime error
Update app.py
Browse files123435678910111213141516171819202122232425262728293031323334353637383940414243import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch
gr.load("models/meta-llama/Meta-Llama-3.1-70B-Instruct").launch()# 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 instruction full_prompt = f"{system_instruction}\nUser: {prompt}\nAssistant:" # Tokenize the full prompt inputs = tokenizer(full_prompt, return_tensors="pt") # Generate model response with torch.no_grad(): outputs = model.generate(**inputs, max_length=150, num_return_sequences=1) # Decode and return response response = tokenizer.decode(outputs[0], skip_special_tokens=True).strip() # Extract only the assistant's response response = 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