AbdurRehman313 commited on
Commit
5ae54b6
·
verified ·
1 Parent(s): 23ea006

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -16
app.py CHANGED
@@ -8,28 +8,65 @@
8
  # sentiment = classifier("I've been waiting for HuggingFace course my whole life.")
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  import streamlit as st
12
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- # Initialize the sentiment-analysis pipeline
15
- classifier = pipeline("sentiment-analysis")
 
16
 
17
- # Streamlit app layout
18
- st.title("Sentiment Analysis with Hugging Face")
19
- st.write("Enter a sentence to analyze its sentiment:")
 
 
 
 
20
 
21
- # Text input for the user
22
- user_input = st.text_input("Sentence", "")
23
 
24
- # Perform sentiment analysis when the user provides input
25
- if user_input:
26
- sentiment = classifier(user_input)
27
- label = sentiment[0]['label']
28
- score = sentiment[0]['score']
29
 
30
- # Display the result
31
- st.write(f"**Sentiment:** {label}")
32
- st.write(f"**Confidence Score:** {score:.4f}")
33
 
34
  # Optional: Add a slider example (unrelated to sentiment analysis)
35
  # x = st.slider('Select a value')
 
8
  # sentiment = classifier("I've been waiting for HuggingFace course my whole life.")
9
 
10
 
11
+ # import streamlit as st
12
+ # from transformers import pipeline
13
+
14
+ # # Initialize the sentiment-analysis pipeline
15
+ # classifier = pipeline("sentiment-analysis")
16
+
17
+ # # Streamlit app layout
18
+ # st.title("Sentiment Analysis with Hugging Face")
19
+ # st.write("Enter a sentence to analyze its sentiment:")
20
+
21
+ # # Text input for the user
22
+ # user_input = st.text_input("Sentence", "")
23
+
24
+ # # Perform sentiment analysis when the user provides input
25
+ # if user_input:
26
+ # sentiment = classifier(user_input)
27
+ # label = sentiment[0]['label']
28
+ # score = sentiment[0]['score']
29
+
30
+ # # Display the result
31
+ # st.write(f"**Sentiment:** {label}")
32
+ # st.write(f"**Confidence Score:** {score:.4f}")
33
+
34
+
35
+
36
+
37
  import streamlit as st
38
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
39
+ import torch
40
+
41
+ # Load the tokenizer and model
42
+ tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
43
+ model = GPT2LMHeadModel.from_pretrained("gpt2-large")
44
+
45
+ def generate_blog(title):
46
+ # Encode the input text
47
+ inputs = tokenizer.encode(title, return_tensors='pt')
48
+
49
+ # Generate the output
50
+ outputs = model.generate(inputs, max_length=500, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
51
+
52
+ # Decode the output text
53
+ blog_post = tokenizer.decode(outputs[0], skip_special_tokens=True)
54
+ return blog_post
55
 
56
+ # Streamlit app
57
+ st.title("Blog Post Generator")
58
+ title = st.text_input("Enter the blog title")
59
 
60
+ if st.button("Generate Blog"):
61
+ if title:
62
+ blog_post = generate_blog(title)
63
+ st.subheader("Generated Blog Post")
64
+ st.write(blog_post)
65
+ else:
66
+ st.warning("Please enter a blog title.")
67
 
 
 
68
 
 
 
 
 
 
69
 
 
 
 
70
 
71
  # Optional: Add a slider example (unrelated to sentiment analysis)
72
  # x = st.slider('Select a value')