Akshayram1 commited on
Commit
4f92c6b
·
verified ·
1 Parent(s): 0df3000

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -1,8 +1,33 @@
1
- # Use a pipeline as a high-level helper
2
  from transformers import pipeline
3
 
4
- messages = [
5
- {"role": "user", "content": "Who are you?"},
6
- ]
7
- pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B")
8
- pipe(messages)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Title of the app
5
+ st.title("Text Generation with DeepSeek-R1-Distill-Qwen-1.5B")
6
+
7
+ # Load the text-generation pipeline
8
+ @st.cache_resource # Cache the model to avoid reloading on every interaction
9
+ def load_model():
10
+ return pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B")
11
+
12
+ model = load_model()
13
+
14
+ # Input text box for user input
15
+ user_input = st.text_area("Enter your prompt:", "Who are you?")
16
+
17
+ # Slider to control the max length of the generated text
18
+ max_length = st.slider("Max length of generated text", min_value=10, max_value=200, value=50)
19
+
20
+ # Button to generate text
21
+ if st.button("Generate Text"):
22
+ if user_input:
23
+ with st.spinner("Generating text..."):
24
+ # Generate text using the pipeline
25
+ messages = [{"role": "user", "content": user_input}]
26
+ output = model(messages, max_length=max_length, num_return_sequences=1)
27
+ generated_text = output[0]["generated_text"]
28
+
29
+ # Display the generated text
30
+ st.success("Generated Text:")
31
+ st.write(generated_text)
32
+ else:
33
+ st.warning("Please enter a prompt!")