Spaces:
Sleeping
Sleeping
Update app.py
Browse files34 unmodified lines3536373839404142434445464748495051525354555634 unmodified lines
# Print the first few entries to verify that it’s loadedprint(dataset["train"][0]) # Prints the first example from the training setfrom transformers import pipeline, AutoModelForCausalLM, AutoTokenizer# Load pre-trained GPT-2 model and tokenizer from Hugging Facemodel_name = "gpt2" # You can use other models such as 'distilgpt2' for faster responses
# Initialize tokenizer and modeltokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)
# Create a pipeline for text generationgenerator = pipeline("text-generation", model=model, tokenizer=tokenizer)def chatbot_response(user_input): # Generate a response using the model response = generator(user_input, max_length=100, num_return_sequences=1) # Extract and return the generated text return response[0]['generated_text']
app.py+16