Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
|
|
|
| 3 |
|
| 4 |
# Load the tokenizer and model
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("OatNapat/finetuned_yelp")
|
|
@@ -8,6 +9,28 @@ model = AutoModelForSequenceClassification.from_pretrained("OatNapat/finetuned_y
|
|
| 8 |
# Create a sentiment analysis pipeline with the explicit tokenizer
|
| 9 |
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
st.title("Sentiment Analysis App")
|
| 12 |
user_input = st.text_input("ป้อนประโยคเพื่อวิเคราะห์ความรู้สึก:")
|
| 13 |
if user_input:
|
|
@@ -30,3 +53,6 @@ if user_input:
|
|
| 30 |
st.write(f"Sentiment: {sentiment_explanation}")
|
| 31 |
st.write(f"Confidence: {sentiment_score:.4f}")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 3 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
|
| 5 |
# Load the tokenizer and model
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("OatNapat/finetuned_yelp")
|
|
|
|
| 9 |
# Create a sentiment analysis pipeline with the explicit tokenizer
|
| 10 |
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 11 |
|
| 12 |
+
# Function to convert text to an image
|
| 13 |
+
def text_to_image(text):
|
| 14 |
+
# Create a blank image with a white background
|
| 15 |
+
image = Image.new("RGB", (500, 100), "white")
|
| 16 |
+
draw = ImageDraw.Draw(image)
|
| 17 |
+
|
| 18 |
+
# Define the font and font size
|
| 19 |
+
font = ImageFont.load_default()
|
| 20 |
+
font_size = 20
|
| 21 |
+
|
| 22 |
+
# Calculate text width and height
|
| 23 |
+
text_width, text_height = draw.textsize(text, font)
|
| 24 |
+
|
| 25 |
+
# Calculate the position to center the text in the image
|
| 26 |
+
x = (image.width - text_width) / 2
|
| 27 |
+
y = (image.height - text_height) / 2
|
| 28 |
+
|
| 29 |
+
# Draw the text on the image
|
| 30 |
+
draw.text((x, y), text, fill="black", font=font)
|
| 31 |
+
|
| 32 |
+
return image
|
| 33 |
+
|
| 34 |
st.title("Sentiment Analysis App")
|
| 35 |
user_input = st.text_input("ป้อนประโยคเพื่อวิเคราะห์ความรู้สึก:")
|
| 36 |
if user_input:
|
|
|
|
| 53 |
st.write(f"Sentiment: {sentiment_explanation}")
|
| 54 |
st.write(f"Confidence: {sentiment_score:.4f}")
|
| 55 |
|
| 56 |
+
# Convert the sentiment explanation to an image
|
| 57 |
+
sentiment_image = text_to_image(sentiment_explanation)
|
| 58 |
+
st.image(sentiment_image, caption="Sentiment Explanation", use_column_width=True)
|