Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install streamlit transformers
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
4 |
+
|
5 |
+
# Load the pipeline
|
6 |
+
model_name = "Orenguteng/Llama-3.1-8B-Lexi-Uncensored-V2"
|
7 |
+
pipe = pipeline("text-generation", model=model_name)
|
8 |
+
|
9 |
+
# Optionally load the tokenizer and model directly (not used directly in this example)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
+
|
13 |
+
def generate_response(prompt):
|
14 |
+
"""Generate a response from the model given a prompt."""
|
15 |
+
response = pipe(prompt, max_length=100, num_return_sequences=1)
|
16 |
+
return response[0]['generated_text']
|
17 |
+
|
18 |
+
# Streamlit Interface
|
19 |
+
st.title("AI Chatbot using Hugging Face")
|
20 |
+
st.markdown("This app uses the Llama-3.1-8B-Lexi-Uncensored-V2 model to generate responses.")
|
21 |
+
|
22 |
+
user_input = st.text_input("Enter your message:", placeholder="Type something here...")
|
23 |
+
|
24 |
+
if st.button("Generate Response"):
|
25 |
+
if user_input:
|
26 |
+
response = generate_response(user_input)
|
27 |
+
st.text_area("Response:", value=response, height=200)
|
28 |
+
else:
|
29 |
+
st.warning("Please enter a message before clicking the button.")
|