Mohammed J commited on
Commit
31b4996
·
verified ·
1 Parent(s): c081c25

Create tabsApp.py

Browse files
Files changed (1) hide show
  1. tabsApp.py +58 -0
tabsApp.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Sentiment Analysis Model
2
+ sentiment_analyzer = pipeline("sentiment-analysis")
3
+
4
+ # Chatbot Model
5
+ chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
6
+
7
+ # Summarization Model
8
+ summarizer = pipeline("summarization")
9
+
10
+ # Sentiment Analysis Function
11
+ def analyze_sentiment(text):
12
+ result = sentiment_analyzer(text)[0]
13
+ sentiment = result['label']
14
+ confidence = round(result['score'], 4)
15
+ return sentiment, confidence
16
+
17
+ # Chatbot Function
18
+ def generate_response(user_input, history=[]):
19
+ history.append(user_input)
20
+ input_text = " ".join(history)
21
+ response = chatbot(input_text, max_length=1000, pad_token_id=50256)
22
+ bot_reply = response[0]['generated_text'][len(input_text):]
23
+ history.append(bot_reply)
24
+ return history, history
25
+
26
+ # Summarization Function
27
+ def summarize_text(text):
28
+ summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
29
+ return summary[0]['summary_text']
30
+
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("# Multi-Function Language Application")
33
+
34
+ with gr.Tabs():
35
+ with gr.TabItem("Sentiment Analysis"):
36
+ gr.Markdown("## Enter text for sentiment analysis:")
37
+ sentiment_input = gr.Textbox(placeholder="Type your text here...")
38
+ sentiment_button = gr.Button("Analyze")
39
+ sentiment_output = gr.Textbox(label="Sentiment")
40
+ confidence_output = gr.Textbox(label="Confidence Score")
41
+ sentiment_button.click(analyze_sentiment, inputs=sentiment_input, outputs=[sentiment_output, confidence_output])
42
+
43
+ with gr.TabItem("Chatbot"):
44
+ gr.Markdown("## Chat with the bot:")
45
+ chatbot_input = gr.Textbox(placeholder="Type your message here...")
46
+ chatbot_button = gr.Button("Send")
47
+ chatbot_output = gr.Chatbot()
48
+ chatbot_state = gr.State([])
49
+ chatbot_button.click(generate_response, inputs=[chatbot_input, chatbot_state], outputs=[chatbot_output, chatbot_state])
50
+
51
+ with gr.TabItem("Summarization"):
52
+ gr.Markdown("## Enter text to summarize:")
53
+ summary_input = gr.Textbox(placeholder="Paste your text here...")
54
+ summary_button = gr.Button("Summarize")
55
+ summary_output = gr.Textbox(label="Summary")
56
+ summary_button.click(summarize_text, inputs=summary_input, outputs=summary_output)
57
+
58
+ demo.launch()