Sanidhya0909 commited on
Commit
a70e17b
1 Parent(s): 4965d09

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +90 -0
  2. requirements.txt +17 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """chat.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1FxpG0gxd0Oigj5CAekXbdwgu7NdtI5sF
8
+ """
9
+
10
+ !pip install -r requirements.txt
11
+
12
+ from transformers import pipeline, Conversation
13
+ import gradio as gr
14
+
15
+ # toy example 1
16
+ pipeline(task="sentiment-analysis")("Love this!")
17
+
18
+ # toy example 2
19
+ pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")("Love this!")
20
+
21
+ # defining classifier
22
+ classifier = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
23
+
24
+ classifier("Hate this.")
25
+
26
+ # we can also pass in a list to classifier
27
+ text_list = ["This is great", \
28
+ "Thanks for nothing", \
29
+ "You've got to work on your face", \
30
+ "You're beautiful, never change!"]
31
+
32
+ classifier(text_list)
33
+
34
+ # if there are multiple target labels, we can return them all
35
+ classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)
36
+
37
+ classifier(text_list[0])
38
+
39
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
40
+
41
+ text = """
42
+ Hugging Face is an AI company that has become a major hub for open-source machine learning.
43
+ Their platform has 3 major elements which allow users to access and share machine learning resources.
44
+ First, is their rapidly growing repository of pre-trained open-source machine learning models for things such as natural language processing (NLP), computer vision, and more.
45
+ Second, is their library of datasets for training machine learning models for almost any task.
46
+ Third, and finally, is Spaces which is a collection of open-source ML apps.
47
+
48
+ The power of these resources is that they are community generated, which leverages all the benefits of open source i.e. cost-free, wide diversity of tools, high quality resources, and rapid pace of innovation.
49
+ While these make building powerful ML projects more accessible than before, there is another key element of the Hugging Face ecosystem—their Transformers library.
50
+ """
51
+ summarized_text = summarizer(text, min_length=5, max_length=140)[0]['summary_text']
52
+ summarized_text
53
+
54
+ classifier(summarized_text)
55
+
56
+ chatbot = pipeline(model="facebook/blenderbot-400M-distill")
57
+
58
+ conversation = chatbot("Hi I'm Shaw, how are you?")
59
+
60
+ conversation
61
+
62
+ conversation = chatbot("Where do you work?")
63
+
64
+ conversation
65
+
66
+ def top3_text_classes(message, history):
67
+ return str(classifier(message)[0][:3]).replace('}, {', '\n').replace('[{', '').replace('}]', '')
68
+
69
+ demo_sentiment = gr.ChatInterface(top3_text_classes, title="Text Sentiment Chatbot", description="Enter your text, and the chatbot will classify the sentiment.")
70
+
71
+ demo_sentiment.launch()
72
+
73
+ def summarizer_bot(message, history):
74
+ return summarizer(message, min_length=5, max_length=140)[0]['summary_text']
75
+
76
+ demo_summarizer = gr.ChatInterface(summarizer_bot, title="Summarizer Chatbot", description="Enter your text, and the chatbot will return the summarized version.")
77
+
78
+ demo_summarizer.launch()
79
+
80
+ message_list = []
81
+ response_list = []
82
+
83
+ def vanilla_chatbot(message, history):
84
+ conversation = chatbot(message)
85
+
86
+ return conversation[0]['generated_text']
87
+
88
+ demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="Vanilla Chatbot", description="Enter text to start chatting.")
89
+
90
+ demo_chatbot.launch()
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==0.21.0
2
+ certifi==2023.7.22
3
+ filelock==3.12.2
4
+ fsspec==2023.6.0
5
+ gradio==3.39.0
6
+ huggingface-hub==0.16.4
7
+ mpmath==1.3.0
8
+ networkx==3.1
9
+ numpy==1.25.1
10
+ pyyaml==6.0.1
11
+ regex==2023.6.3
12
+ safetensors==0.3.1
13
+ sympy==1.12
14
+ tokenizers==0.13.3
15
+ torch==2.0.1
16
+ tqdm==4.65.0
17
+ transformers==4.31.0