vivekkumarbarman commited on
Commit
1e537fd
1 Parent(s): 30d4848

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -1,14 +1,28 @@
1
  import gradio as gr
2
- from textblob import TextBlob
3
-
4
- # Define the sentiment analysis function
5
- def analyze_sentiment(text):
6
- blob = TextBlob(text)
7
- polarity = blob.sentiment.polarity
8
- subjectivity = blob.sentiment.subjectivity
9
- sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE"
10
- return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}"
11
-
12
- # Create a Gradio interface
13
- iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
14
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
+
4
+ # Load the GPT-2 model and tokenizer
5
+ model_name = "gpt2"
6
+ model = GPT2LMHeadModel.from_pretrained(model_name)
7
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
8
+
9
+ # Define the sentence completion function
10
+ def complete_sentence(sentence):
11
+ input_ids = tokenizer.encode(sentence, return_tensors="pt")
12
+ output = model.generate(input_ids, max_length=50, num_return_sequences=1)
13
+ completed_sentence = tokenizer.decode(output[0], skip_special_tokens=True)
14
+ return completed_sentence
15
+
16
+ # Create the Gradio interface
17
+ iface = gr.Interface(
18
+ fn=complete_sentence,
19
+ inputs="text",
20
+ outputs="text",
21
+ title="Sentence Completion",
22
+ description="Enter a sentence to complete",
23
+ example="I love to"
24
+ )
25
+
26
+ # Launch the Gradio interface
27
+ if __name__ == "__main__":
28
+ iface.launch()