Spaces:
Sleeping
Sleeping
Initial Draft
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
################################
|
4 |
####### Generic functions ######
|
@@ -23,25 +24,77 @@ def option_change():
|
|
23 |
translation_eng2frn()
|
24 |
|
25 |
def button_clicked():
|
26 |
-
st.session_state.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def sentiment_analysis():
|
29 |
st.session_state.input_text="I've been waiting for a HuggingFace course my whole life."
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def zero_shot_classification():
|
32 |
st.session_state.input_text="This is a course about the transformers library"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def text_generation():
|
35 |
st.session_state.input_text="In this course, we will teach you how to"
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def mask_filling():
|
38 |
st.session_state.input_text="This course will teach you all about <mask> models."
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def named_entity_recognition():
|
41 |
st.session_state.input_text="My name is Sylvain and I work at Hugging Face in Brooklyn."
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def qna():
|
44 |
st.session_state.input_text="My name is Sylvain and I work at Hugging Face in Brooklyn"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def summarization():
|
47 |
st.session_state.input_text= """America has changed dramatically during recent years. Not only has the number of
|
@@ -63,18 +116,27 @@ def summarization():
|
|
63 |
suffers an increasingly serious decline in the number of engineering graduates
|
64 |
and a lack of well-educated engineers.
|
65 |
"""
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def translation_eng2frn():
|
68 |
st.session_state.input_text= "This course is produced by Hugging Face."
|
|
|
69 |
|
70 |
-
|
|
|
|
|
|
|
71 |
################################
|
72 |
####### Display of data ########
|
73 |
################################
|
74 |
st.set_page_config(layout='wide')
|
75 |
|
76 |
# Title
|
77 |
-
st.title("LLM Basics Demo
|
78 |
|
79 |
# 3 Column Layout
|
80 |
col1, col2, col3 = st.columns(3)
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
################################
|
5 |
####### Generic functions ######
|
|
|
24 |
translation_eng2frn()
|
25 |
|
26 |
def button_clicked():
|
27 |
+
if st.session_state.action_type=="Sentiment Analysis":
|
28 |
+
sentiment_analysis_btn()
|
29 |
+
elif st.session_state.action_type=="Zero-shot Classification":
|
30 |
+
zero_shot_classification_btn()
|
31 |
+
elif st.session_state.action_type=="Text Generation":
|
32 |
+
text_generation_btn()
|
33 |
+
elif st.session_state.action_type=="Mask Filling":
|
34 |
+
mask_filling_btn()
|
35 |
+
elif st.session_state.action_type=="Named Entity Recognition":
|
36 |
+
named_entity_recognition_btn()
|
37 |
+
elif st.session_state.action_type=="Question & Answering":
|
38 |
+
qna_btn()
|
39 |
+
elif st.session_state.action_type=="Summarization":
|
40 |
+
summarization_btn()
|
41 |
+
elif st.session_state.action_type=="English to French Translation":
|
42 |
+
translation_eng2frn_btn()
|
43 |
|
44 |
def sentiment_analysis():
|
45 |
st.session_state.input_text="I've been waiting for a HuggingFace course my whole life."
|
46 |
+
st.session_state.output_text=""
|
47 |
+
|
48 |
+
def sentiment_analysis_btn():
|
49 |
+
classifier = pipeline("sentiment-analysis")
|
50 |
+
st.session_state.output_text=classifier(st.session_state.input_text)
|
51 |
|
52 |
def zero_shot_classification():
|
53 |
st.session_state.input_text="This is a course about the transformers library"
|
54 |
+
st.session_state.output_text=""
|
55 |
+
|
56 |
+
def zero_shot_classification_btn():
|
57 |
+
classifier = pipeline("zero-shot-classification")
|
58 |
+
st.session_state.output_text=classifier(
|
59 |
+
st.session_state.input_text,
|
60 |
+
candidate_labels=["education", "politics", "business"],
|
61 |
+
)
|
62 |
|
63 |
def text_generation():
|
64 |
st.session_state.input_text="In this course, we will teach you how to"
|
65 |
+
st.session_state.output_text=""
|
66 |
+
|
67 |
+
def text_generation_btn():
|
68 |
+
generator = pipeline("text-generation")
|
69 |
+
st.session_state.output_text=generator(st.session_state.input_text)
|
70 |
|
71 |
def mask_filling():
|
72 |
st.session_state.input_text="This course will teach you all about <mask> models."
|
73 |
+
st.session_state.output_text=""
|
74 |
+
|
75 |
+
def mask_filling_btn():
|
76 |
+
unmasker = pipeline("fill-mask")
|
77 |
+
st.session_state.output_text=unmasker(st.session_state.input_text, top_k=2)
|
78 |
|
79 |
def named_entity_recognition():
|
80 |
st.session_state.input_text="My name is Sylvain and I work at Hugging Face in Brooklyn."
|
81 |
+
st.session_state.output_text=""
|
82 |
+
|
83 |
+
def named_entity_recognition_btn():
|
84 |
+
ner = pipeline("ner", grouped_entities=True)
|
85 |
+
st.session_state.output_text=ner(st.session_state.input_text)
|
86 |
|
87 |
def qna():
|
88 |
st.session_state.input_text="My name is Sylvain and I work at Hugging Face in Brooklyn"
|
89 |
+
st.session_state.output_text=""
|
90 |
+
|
91 |
+
def qna_btn():
|
92 |
+
question_answerer = pipeline("question-answering")
|
93 |
+
st.session_state.output_text="Questionn: Where do I work?\n Answer: "
|
94 |
+
st.session_state.output_text=st.session_state.output_text + question_answerer(
|
95 |
+
question=st.session_state.input_text,
|
96 |
+
context="My name is Sylvain and I work at Hugging Face in Brooklyn",
|
97 |
+
)
|
98 |
|
99 |
def summarization():
|
100 |
st.session_state.input_text= """America has changed dramatically during recent years. Not only has the number of
|
|
|
116 |
suffers an increasingly serious decline in the number of engineering graduates
|
117 |
and a lack of well-educated engineers.
|
118 |
"""
|
119 |
+
st.session_state.output_text=""
|
120 |
+
|
121 |
+
def summarization_btn():
|
122 |
+
summarizer = pipeline("summarization")
|
123 |
+
st.session_state.output_text=summarizer(st.session_state.input_text)
|
124 |
|
125 |
def translation_eng2frn():
|
126 |
st.session_state.input_text= "This course is produced by Hugging Face."
|
127 |
+
st.session_state.output_text=""
|
128 |
|
129 |
+
def translation_eng2frn_btn():
|
130 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
|
131 |
+
st.session_state.output_text=translator(st.session_state.input_text)
|
132 |
+
|
133 |
################################
|
134 |
####### Display of data ########
|
135 |
################################
|
136 |
st.set_page_config(layout='wide')
|
137 |
|
138 |
# Title
|
139 |
+
st.title("LLM Basics Demo")
|
140 |
|
141 |
# 3 Column Layout
|
142 |
col1, col2, col3 = st.columns(3)
|