Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
if st.button('Submit'):
|
| 8 |
-
if text:
|
| 9 |
-
out = pipe(text)
|
| 10 |
-
st.write(out)
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# pipe = pipeline('sentiment-analysis')
|
| 5 |
+
# text= st.text_area('enter some text')
|
| 6 |
+
|
| 7 |
+
# if st.button('Submit'):
|
| 8 |
+
# if text:
|
| 9 |
+
# out = pipe(text)
|
| 10 |
+
# st.write(out)
|
| 11 |
+
|
| 12 |
import streamlit as st
|
| 13 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 14 |
+
|
| 15 |
+
# Load the GPT tokenizer and model
|
| 16 |
+
tokenizer = AutoTokenizer.from_pretrained("sshleifer/tiny-gpt2")
|
| 17 |
+
model = AutoModelForCausalLM.from_pretrained("sshleifer/tiny-gpt2")
|
| 18 |
+
|
| 19 |
+
# Load the sentiment analysis pipeline
|
| 20 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 21 |
+
|
| 22 |
+
# Text input field
|
| 23 |
+
user_input = st.text_area("Enter your prompt:")
|
| 24 |
+
|
| 25 |
+
if st.button("Submit"):
|
| 26 |
+
if user_input:
|
| 27 |
+
# Generate text using the GPT model
|
| 28 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
| 29 |
+
generated_ids = model.generate(**inputs)
|
| 30 |
+
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 31 |
+
|
| 32 |
+
# Perform sentiment analysis on both original and generated text
|
| 33 |
+
original_sentiment = sentiment_pipeline(user_input)
|
| 34 |
+
generated_sentiment = sentiment_pipeline(generated_text)
|
| 35 |
+
|
| 36 |
+
# Display the results
|
| 37 |
+
st.write("Original Text:")
|
| 38 |
+
st.write(user_input)
|
| 39 |
+
st.write("Original Text Sentiment:", original_sentiment)
|
| 40 |
|
| 41 |
+
st.write("Generated Text:")
|
| 42 |
+
st.write(generated_text)
|
| 43 |
+
st.write("Generated Text Sentiment:", generated_sentiment)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|