Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,35 @@
|
|
| 1 |
-
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 4 |
-
from
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 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 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from transformers import AutoModelForSequenceClassification
|
| 4 |
+
from transformers import AutoTokenizer
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def main():
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
st.title("yelp2024fall Test")
|
| 12 |
+
st.write("Enter a sentence for analysis:")
|
| 13 |
+
|
| 14 |
+
user_input = st.text_input("")
|
| 15 |
+
if user_input:
|
| 16 |
+
# Approach: AutoModel
|
| 17 |
+
model2 = AutoModelForSequenceClassification.from_pretrained("isom5240/CustomModel_yelp2025L1",
|
| 18 |
+
num_labels=5)
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 20 |
+
|
| 21 |
+
inputs = tokenizer(user_input,
|
| 22 |
+
padding=True,
|
| 23 |
+
truncation=True,
|
| 24 |
+
return_tensors='pt')
|
| 25 |
+
|
| 26 |
+
outputs = model2(**inputs)
|
| 27 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 28 |
+
predictions = predictions.cpu().detach().numpy()
|
| 29 |
+
# Get the index of the largest output value
|
| 30 |
+
max_index = np.argmax(predictions)
|
| 31 |
+
st.write(f"result (AutoModel) - Label: {max_index}")
|
| 32 |
+
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|