Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,20 @@
|
|
| 1 |
-
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import io
|
| 6 |
-
|
| 7 |
-
# function part
|
| 8 |
-
def generate_image_caption(image):
|
| 9 |
-
"""Generates a caption for the given image using a pre-trained model."""
|
| 10 |
-
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 11 |
-
|
| 12 |
-
# Generate caption
|
| 13 |
-
result = img2caption(image)
|
| 14 |
-
return result[0]['generated_text']
|
| 15 |
-
|
| 16 |
-
# text2story
|
| 17 |
-
def text2story(text):
|
| 18 |
-
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 19 |
-
story_text = pipe(text)[0]['generated_text']
|
| 20 |
-
return story_text
|
| 21 |
|
| 22 |
def main():
|
| 23 |
-
|
| 24 |
-
st.title("Streamlit Demo on Hugging Face")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
st.write("
|
| 28 |
-
|
| 29 |
-
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
st.
|
| 37 |
-
image_caption = generate_image_caption(image)
|
| 38 |
-
st.write(image_caption)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def main():
|
| 5 |
+
sentiment_pipeline = pipeline(model="distilbert-base-uncased-finetuned-sst-2-english")
|
|
|
|
| 6 |
|
| 7 |
+
st.title("Sentiment Analysis with HuggingFace Spaces")
|
| 8 |
+
st.write("Enter a sentence to analyze its sentiment:")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
user_input = st.text_input("")
|
| 11 |
+
if user_input:
|
| 12 |
+
result = sentiment_pipeline(user_input)
|
| 13 |
+
sentiment = result[0]["label"]
|
| 14 |
+
confidence = result[0]["score"]
|
| 15 |
|
| 16 |
+
st.write(f"Sentiment: {sentiment}")
|
| 17 |
+
st.write(f"Confidence: {confidence:.2f}")
|
|
|
|
|
|
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
| 20 |
main()
|