marksverdhei commited on
Commit
065c3c8
1 Parent(s): 947b688
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +56 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Saved You A Click
3
- emoji: 🐨
4
  colorFrom: pink
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 3.0.3
8
  app_file: app.py
 
1
  ---
2
  title: Saved You A Click
3
+ emoji: 📰🖱️
4
  colorFrom: pink
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 3.0.3
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from newspaper import Article
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ ta_pipeline = pipeline(model="marksverdhei/unifiedqa-large-reddit-syac")
6
+ ta_pipeline.tokenizer.model_max_length = 2048
7
+ ta_pipeline.model.config.max_length = 300
8
+
9
+ description = """
10
+ Enter the url for a clickbait article, or the answer and content.
11
+ We will provide the answer to the clickbait title.
12
+ Disclaimer: the model can generate wrong information. Read more about the model [here](https://huggingface.co/marksverdhei/unifiedqa-large-reddit-syac).
13
+ """
14
+
15
+
16
+ def fetch_article_content(url):
17
+ article = Article(url)
18
+ article.download()
19
+ article.parse()
20
+
21
+ if not (article.title and article.text):
22
+ raise Exception("Unable to fetch article. Try copy-pasting in the text fields instead.")
23
+
24
+ return article.title, article.text
25
+
26
+
27
+ def predict(title, body):
28
+ title = title.lower()
29
+ body = body.lower()
30
+ input_text = title + r" \n " + body
31
+ output = ta_pipeline(input_text, truncation=True)
32
+ output_text = output[0]["generated_text"]
33
+ return output_text
34
+
35
+
36
+ def predict_from_inputs(url, title, body):
37
+ if url:
38
+ title, body = fetch_article_content(url)
39
+
40
+ if title and body:
41
+ return title, predict(title, body)
42
+ else:
43
+ raise Exception("You must supply either url or title and body")
44
+
45
+
46
+ gr.Interface(
47
+ fn=predict_from_inputs,
48
+ inputs=["text", "text", "text"],
49
+ outputs=[
50
+ gr.Textbox(label="title"),
51
+ gr.Textbox(label="answer")
52
+ ],
53
+
54
+ title="Saved you a click!",
55
+ description=description,
56
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ newspaper3k
2
+ gradio
3
+ transformers