Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,12 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""Copy of [Student]_Module_2_Session_3.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colab.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/1pmME28f5Z7SNxUoX5va3W-90XP5zPnQu
|
8 |
-
|
9 |
-
Installations
|
10 |
-
"""
|
11 |
-
|
12 |
-
!pip install gradio
|
13 |
-
!pip install transformers
|
14 |
-
|
15 |
-
"""#Let's build a demo for a sentiment analysis task !
|
16 |
-
|
17 |
-
Import the necessary modules :
|
18 |
-
"""
|
19 |
-
|
20 |
-
from transformers import pipeline
|
21 |
import gradio as gr
|
22 |
|
23 |
-
"
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
"""Test the pipeline on these reviews (you can also test on your own reviews) :"""
|
28 |
-
|
29 |
-
#"I really enjoyed my stay !"
|
30 |
-
#"Worst rental I ever got"
|
31 |
-
|
32 |
-
sentiment("I really enjoyed my stay !")
|
33 |
-
|
34 |
-
"""What is the format of the output ? How can you get only the sentiment or the confidence score ?"""
|
35 |
-
|
36 |
-
print(sentiment("I really enjoyed my stay !")[0]['label'])
|
37 |
-
print(sentiment("I really enjoyed my stay !")[0]['score'])
|
38 |
-
print(sentiment("Worst rental I ever got")[0]['label'])
|
39 |
-
print(sentiment("Worst rental I ever got")[0]['score'])
|
40 |
-
|
41 |
-
"""Create a function that takes a text in input, and returns a sentiment, and a confidence score as 2 different variables"""
|
42 |
-
|
43 |
-
def get_sentiment(text):
|
44 |
-
return sentiment(text)[0]['label'], sentiment(text)[0]['score']
|
45 |
-
|
46 |
-
"""Build an interface for the app using Gradio.
|
47 |
-
The customer wants this result :"""
|
48 |
-
|
49 |
-
interface = gr.Interface(fn=get_sentiment,
|
50 |
-
inputs=gr.Textbox(lines=1, label="Enter the review:"),
|
51 |
-
outputs=[gr.Text(label='Sentiment:'),
|
52 |
-
gr.Text(label='Score:')])
|
53 |
-
|
54 |
-
interface.launch()
|
55 |
-
|
56 |
-
ar_sentiment = pipeline("sentiment-analysis", model='CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment')
|
57 |
-
|
58 |
-
ar_sentiment('انا احب ذلك')
|
59 |
-
|
60 |
-
def get_ar_sentiment(text):
|
61 |
-
return ar_sentiment(text)[0]['label'], ar_sentiment(text)[0]['score']
|
62 |
|
63 |
-
interface = gr.Interface(
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
|
68 |
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
description = "Story generation with GPT-2"
|
4 |
+
title = "Generate your own story"
|
5 |
+
examples = [["Adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
interface = gr.Interface.load("huggingface/pranavpsv/gpt2-genre-story-generator",
|
8 |
+
description=description,
|
9 |
+
examples=examples
|
10 |
+
)
|
11 |
|
12 |
interface.launch()
|