Spaces:
Running
Running
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the model pipeline | |
| # Cache the model to avoid reloading | |
| def load_pipeline(): | |
| model_name = "Orenguteng/Llama-3.1-8B-Lexi-Uncensored-V2" | |
| return pipeline("text-generation", model=model_name) | |
| pipe = load_pipeline() | |
| # App UI | |
| st.set_page_config(page_title="Hugging Face Chatbot", layout="centered") | |
| st.title("π€ AI Chatbot") | |
| st.markdown( | |
| """ | |
| Welcome to the **AI Chatbot** powered by Hugging Face's Llama-3.1-8B-Lexi-Uncensored-V2 model. | |
| Enter your message below to get started! | |
| """ | |
| ) | |
| # Input Box | |
| user_input = st.text_area( | |
| "Your Message", | |
| placeholder="Type your message here...", | |
| height=100 | |
| ) | |
| # Generate Button | |
| if st.button("Generate Response"): | |
| if user_input.strip(): | |
| with st.spinner("Generating response..."): | |
| response = pipe(user_input, max_length=150, num_return_sequences=1) | |
| st.text_area("Response", value=response[0]['generated_text'], height=200) | |
| else: | |
| st.warning("Please enter a message before clicking the button.") | |