spedrox-sac commited on
Commit
b93b0a9
·
verified ·
1 Parent(s): 866e218

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
-
4
  # Initialize the text generation pipeline
5
  pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device=-1)
6
-
7
  # Streamlit app
8
  st.title("Text Generation with Qwen Model")
9
 
@@ -15,7 +15,7 @@ if st.button("Generate"):
15
  messages = [{"role": "user", "content": user_input}]
16
  output = pipe(messages, max_new_tokens=50) # Adjust max_new_tokens as needed
17
  generated_text = output[0]['generated_text']
18
-
19
  # Display the generated text
20
  st.write("Generated Response:")
21
- st.write(generated_text)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from langchain_core.output_parsers import StrOutputParser
4
  # Initialize the text generation pipeline
5
  pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device=-1)
6
+ parser = StrOutputParser()
7
  # Streamlit app
8
  st.title("Text Generation with Qwen Model")
9
 
 
15
  messages = [{"role": "user", "content": user_input}]
16
  output = pipe(messages, max_new_tokens=50) # Adjust max_new_tokens as needed
17
  generated_text = output[0]['generated_text']
18
+ result = parser.invoke(generated_text)
19
  # Display the generated text
20
  st.write("Generated Response:")
21
+ st.write(result)