Rahulkwaa/RomanticChatBot
0
1import streamlit as st2from transformers import AutoModelForCausalLM, AutoTokenizer3import torch4 5# Load Hugging Face model6model_name = "meta-llama/Llama-2-7b-chat-hf"7tokenizer = AutoTokenizer.from_pretrained(model_name)8 9# Check if GPU is available, otherwise use CPU10device = "cuda" if torch.cuda.is_available() else "cpu"11 12model = AutoModelForCausalLM.from_pretrained(13 model_name, 14 device_map="auto" if device == "cuda" else None, 15 torch_dtype=torch.float16 if device == "cuda" else torch.float3216).to(device)17 18# Define chatbot logic19def chatbot_response(user_message):20 inputs = tokenizer(user_message, return_tensors="pt").to(device)21 outputs = model.generate(inputs.input_ids, max_length=150, temperature=0.8, top_p=0.95)22 response = tokenizer.decode(outputs[0], skip_special_tokens=True)23 return response24 25# Streamlit UI26st.title("Romantic Chatbot")27 28# Chatbox for user input29user_input = st.text_area("Type your message...", height=150)30 31# Handle user input and show response32if user_input:33 response = chatbot_response(user_input)34 st.text_area("Response:", value=response, height=150, max_chars=1000)35 