Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the text generation pipeline with optimizations
|
5 |
+
pipe = pipeline(
|
6 |
+
"text-generation",
|
7 |
+
model="meta-llama/Llama-3.2-1B",
|
8 |
+
device=-1, # Ensure it runs on CPU
|
9 |
+
use_fast=True, # Use fast tokenizer
|
10 |
+
)
|
11 |
+
|
12 |
+
# Streamlit app
|
13 |
+
st.title("Llama3.2-1B")
|
14 |
+
|
15 |
+
# Text input from the user
|
16 |
+
user_input = st.text_input("Enter your message:", "Delete this and write your query?")
|
17 |
+
|
18 |
+
# Generate text when the button is clicked
|
19 |
+
if st.button("Generate"):
|
20 |
+
messages = [{"role": "user", "content": user_input}]
|
21 |
+
# Reduce max_new_tokens for faster generation
|
22 |
+
output = pipe(messages, max_new_tokens=150) # Adjust as needed for speed
|
23 |
+
generated_text = output[0]['generated_text']
|
24 |
+
|
25 |
+
# Display the generated text
|
26 |
+
st.write("Generated Response:")
|
27 |
+
st.write(generated_text)
|