Nlpeva commited on
Commit
759f064
1 Parent(s): 11711a8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import pipeline
4
+
5
+ def text_pipelines(text_txt, text_pipes):
6
+ if text_pipes == "Translate En to Fr":
7
+ en_fr_translator = pipeline("translation_en_to_fr")
8
+ output = en_fr_translator(f"{text_txt}")[0]["translation_text"]
9
+ elif text_pipes == "Text Generation":
10
+ text_generation = pipeline("text-generation")
11
+ output = text_generation(f"{text_txt}")[0]["generated_text"]
12
+ elif text_pipes == "Sentiment Analysis":
13
+ sentiment_analysis = pipeline("sentiment-analysis")
14
+ output = sentiment_analysis(f"{text_txt}")
15
+ return output
16
+
17
+ def cat_images(cat_slider):
18
+ if cat_slider < 10:
19
+ images = ["./images/dog1.jpg", "./images/dog2.jpg"]
20
+ if cat_slider >= 10:
21
+ images = ["./images/cat1.jpg", "./images/cat2.jpg", "./images/cat3.jpg"]
22
+ return images
23
+
24
+ with gr.Blocks() as Blocks:
25
+ with gr.Row():
26
+ gr.Markdown("<h1>🤗 Hugging Face Pipelines 🤗</h1> <h2>🥳🥳 Welcome to the block party! 🥳🥳</h2>")
27
+
28
+ with gr.Row():
29
+ with gr.Column():
30
+ gr.Markdown("<br><br><br><br>")
31
+ with gr.Tabs():
32
+ with gr.TabItem("Audio Classification"):
33
+ gr.Markdown("<h3>🔊Audio Classification</h3><p>Classifies your audio!</p><p>You could: Label emotions, such as happy or sad.😊😢</p>")
34
+ with gr.TabItem("Automatic Speech Recognition"):
35
+ gr.Markdown("<h3>💬Automatic Speech Recognition</h3><p>Recognizes speech automatically!</p><p>You could: Create transcripts. 📃</p>")
36
+ with gr.TabItem("Image Segmentation"):
37
+ gr.Markdown("<h3>🖼️Image Segmentation</h3><p>Segments images!</p><p>You could: Highlight the area that has a cat</p")
38
+ gr.Markdown("<br><br><p>There are all kinds of pipelines: image, text, audio!</p><p>⬇️ Try some of them out below ⬇️</p>")
39
+ with gr.Column():
40
+ gr.Markdown("<br><br>")
41
+ with gr.Column():
42
+ with gr.Tabs():
43
+ with gr.TabItem("What's a Pipeline?!"):
44
+ gr.Markdown("Easy mode! Use the pipeline() to streamline everything in like 4 lines of code. It's even smart enough to pick a model for you if you want. 🤗")
45
+ with gr.TabItem("What's Gradio?"):
46
+ gr.Markdown("The way to make layouts super quickly! You can add dropdown boxes, radio buttons, checkboxes and more which will be able to change the inputs to your functions.")
47
+ with gr.Tabs():
48
+ with gr.TabItem("Block Party!"):
49
+ gr.Markdown("<p>This was created during Hugging Face's Block Party to celebrate the release of Gradio's new block function.</p><p>The app was created using a block with 4 rows, and the info box you are reading was made using Gradio Tabs!</p><p>Thank you ever so much for your likes! ❤️</p>")
50
+ with gr.TabItem("Cat Tax"):
51
+ cat_slider = gr.Slider(0, 100, label="Percentage you like cats:")
52
+ cats_but = gr.Button("Show cute cats!")
53
+ gallery = gr.Gallery()
54
+
55
+ with gr.Row():
56
+ gr.Markdown("<h1>🚀 Test Out Some Text Pipelines! 🚀")
57
+
58
+ with gr.Row():
59
+ text_txt = gr.Textbox("Enter something fun here!", label="1. Type some text:")
60
+ text_pipes = gr.Dropdown(["Translate En to Fr", "Text Generation", "Sentiment Analysis"], label="2. Pick your Pipeline:")
61
+ go_but = gr.Button("3. It's go time!")
62
+ text = gr.Textbox("Hit the go button to see results here", label="4. See the output!")
63
+
64
+
65
+ cats_but.click(cat_images, inputs=cat_slider, outputs=gallery)
66
+ go_but.click(text_pipelines, inputs=[text_txt, text_pipes], outputs=text)
67
+ Blocks.launch()