adi-123 commited on
Commit
837232b
1 Parent(s): 40399bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -11,10 +11,10 @@ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
11
  sentiment_analysis = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
12
 
13
  # Streamlit UI
14
- st.title("GPT-2 Movie Review Sentiment Analysis")
15
 
16
  # Input text for sentiment analysis
17
- input_text = st.text_area("Enter movie review:", "")
18
 
19
  # Choose analysis type
20
  analysis_type = st.radio("Select analysis type:", ["Zero-shot", "One-shot", "Few-shot"])
@@ -24,15 +24,20 @@ if st.button("Analyze Sentiment"):
24
  if analysis_type == "Zero-shot":
25
  results = sentiment_analysis(input_text)
26
  elif analysis_type == "One-shot":
27
- prompt = "This movie review is about a "
28
- input_text = prompt + input_text
29
- results = sentiment_analysis(input_text)
30
  elif analysis_type == "Few-shot":
31
- prompt = "This movie review is about a positive topic. " + input_text
32
- results = sentiment_analysis(prompt)
 
 
 
 
 
 
33
 
34
  # Display results
35
  st.write("Sentiment:", results[0]['label'])
36
  st.write("Confidence:", results[0]['score'])
37
 
38
- # Note: This is a basic example, and you might need to fine-tune it based on your specific use case and requirements.
 
11
  sentiment_analysis = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
12
 
13
  # Streamlit UI
14
+ st.title("GPT-2 Movie Sentiment Analysis")
15
 
16
  # Input text for sentiment analysis
17
+ input_text = st.text_area("Enter movie sentiment:", "")
18
 
19
  # Choose analysis type
20
  analysis_type = st.radio("Select analysis type:", ["Zero-shot", "One-shot", "Few-shot"])
 
24
  if analysis_type == "Zero-shot":
25
  results = sentiment_analysis(input_text)
26
  elif analysis_type == "One-shot":
27
+ # Use the input text as the single example
28
+ results = sentiment_analysis(f"This movie is about {input_text}")
 
29
  elif analysis_type == "Few-shot":
30
+ # Use multiple examples for few-shot analysis
31
+ examples = [
32
+ f"This movie sets an example of bad ethics. {input_text}",
33
+ f"I loved this movie. {input_text}",
34
+ f"The movie is neither good nor bad. {input_text}"
35
+ ]
36
+ input_text = " ".join(examples)
37
+ results = sentiment_analysis(input_text)
38
 
39
  # Display results
40
  st.write("Sentiment:", results[0]['label'])
41
  st.write("Confidence:", results[0]['score'])
42
 
43
+ # Note: This is a basic example, and you might need to fine-tune it based on your specific use case and requirements.