Spaces:
Sleeping
Sleeping
spedrox-sac
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
from langchain_core.output_parsers import StrOutputParser
|
4 |
|
5 |
-
# Initialize the text generation pipeline
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
# Streamlit app
|
11 |
-
st.title("Optimized
|
12 |
|
13 |
# Text input from the user
|
14 |
-
user_input = st.
|
15 |
|
16 |
# Generate text when the button is clicked
|
17 |
if st.button("Generate"):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
st.write("Generated Responses:")
|
27 |
-
for i, output in enumerate(outputs):
|
28 |
-
generated_text = output['generated_text']
|
29 |
-
result = parser.invoke(generated_text)
|
30 |
-
st.write(f"Input {i+1}: {messages[i]}")
|
31 |
-
st.write(f"Response {i+1}: {result}\n")
|
|
|
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="Qwen/Qwen2.5-0.5B-Instruct",
|
8 |
+
device=-1, # Ensure it runs on CPU
|
9 |
+
use_fast=True, # Use fast tokenizer
|
10 |
+
)
|
11 |
|
12 |
# Streamlit app
|
13 |
+
st.title("Optimized Text Generation with Qwen Model")
|
14 |
|
15 |
# Text input from the user
|
16 |
+
user_input = st.text_input("Enter your message:", "Who are you?")
|
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=30) # 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)
|
|
|
|
|
|
|
|
|
|
|
|