Harshavarma04 commited on
Commit
bc22532
1 Parent(s): 54f5eab

Delete analyzer.py

Browse files
Files changed (1) hide show
  1. analyzer.py +0 -64
analyzer.py DELETED
@@ -1,64 +0,0 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
-
4
- # Initialize sentiment analysis pipeline
5
- sentiment_pipeline = pipeline("sentiment-analysis")
6
-
7
- # Use a sarcasm detection model
8
- sarcasm_model_name = "mrm8488/t5-base-finetuned-sarcasm-twitter" # Correct model name for sarcasm detection
9
-
10
- # Create the sarcasm detection pipeline
11
- sarcasm_pipeline = pipeline("text2text-generation", model=sarcasm_model_name)
12
-
13
- def classify_sentence(sentence):
14
- # Detect sarcasm
15
- sarcasm_result = sarcasm_pipeline(sentence)[0]['generated_text']
16
- is_sarcastic = sarcasm_result.strip().lower() == 'true'
17
-
18
- # Detect sentiment
19
- sentiment_result = sentiment_pipeline(sentence)[0]
20
- sentiment_label = sentiment_result['label']
21
- sentiment_score = sentiment_result['score']
22
-
23
- # Determine sentiment
24
- if sentiment_label == "NEGATIVE":
25
- sentiment = "negative"
26
- elif sentiment_label == "POSITIVE":
27
- sentiment = "positive"
28
- else:
29
- sentiment = "neutral"
30
-
31
- # Handle sarcasm
32
- if is_sarcastic:
33
- sentiment += " (sarcastic)"
34
-
35
- return sentiment
36
-
37
- # Streamlit app
38
- st.title("Sentence Analyzer")
39
-
40
- # User input
41
- sentence = st.text_input("Enter a sentence:", "")
42
-
43
- if st.button("Analyze"):
44
- if sentence:
45
- classification = classify_sentence(sentence)
46
- st.write(f"Sentence: {sentence}")
47
- st.write(f"Classification: {classification}")
48
- else:
49
- st.write("Please enter a sentence to analyze.")
50
-
51
- # Example sentences
52
- st.subheader("Example Sentences")
53
- example_sentences = [
54
- "they are so beautiful",
55
- "This is the best day of my life.",
56
- "I'm not happy with your work.",
57
- "Yeah,you are not a good person!"
58
- ]
59
-
60
- if st.button("Analyze Example Sentences"):
61
- for sentence in example_sentences:
62
- st.write(f"Sentence: {sentence}")
63
- st.write(f"Classification: {classify_sentence(sentence)}")
64
- st.write()