import streamlit as st from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer def main(): # Load the model and tokenizer model_name = "microsoft/resnet-50" model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) # Initialize the pipeline sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) st.title("Sentiment Analysis with HuggingFace Spaces") st.write("Enter a sentence to analyze its sentiment:") user_input = st.text_input("") if user_input: try: # Debugging: Print the tokenized input tokenized_input = tokenizer(user_input, return_tensors="pt") st.write("Tokenized Input:", tokenized_input) result = sentiment_pipeline(user_input) sentiment = result["label"] confidence = result["score"] st.write(f"Sentiment: {sentiment}") st.write(f"Confidence: {confidence:.2f}") except Exception as e: st.write(f"Error: {e}") if __name__ == "__main__": main()