app file added
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# API endpoint
|
5 |
+
API_URL = "https://api-inference.huggingface.co/models/Rahmat82/dialogsum_ds"
|
6 |
+
import os
|
7 |
+
SECRET_KEY = os.environ.get("summarizer")
|
8 |
+
|
9 |
+
def summarize(text):
|
10 |
+
headers = {"Authorization": f"Bearer {SECRET_KEY}"}
|
11 |
+
data = {"inputs": text}
|
12 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
13 |
+
|
14 |
+
if response.status_code == 200:
|
15 |
+
return response.json()[0]["generated_text"]
|
16 |
+
else:
|
17 |
+
return "Error occurred. Please try again."
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
theme=gr.themes.Soft(),
|
21 |
+
fn=summarize,
|
22 |
+
title="Dialogue Summarizer",
|
23 |
+
description="<b> NOTE: </b> Can be a bit slower here 🐢 <h3>On GPU it is much faster 🚀</h3>",
|
24 |
+
inputs=gr.Textbox(label="Write your dialogue text here", lines=10),
|
25 |
+
outputs=gr.Textbox(label="Summary"),
|
26 |
+
submit_btn=gr.Button("Summarize", variant="primary"),
|
27 |
+
allow_flagging='never',
|
28 |
+
|
29 |
+
examples=[
|
30 |
+
"""
|
31 |
+
For 265 years, 104 letters written to French sailors sat on a shelf in the U.K. They were never opened. They have just been read for the first time. The letters were on a French warship captured by Britain in 1758. The French sailors did not have time to open and read their mail. The letters were put in storage in an archive and forgotten about. They gathered dust for two and a half centuries. A researcher said many of the letters were love letters. A group of researchers studied the letters. They said the writing gave a rare look back into history. The writers were rich and poor. They were fiancés, parents, siblings and wives. They all had different levels of literacy. A researcher said the letters showed how we manage things like pandemics and wars. He said the letters were similar to what people write about today. They were about staying in touch, caring for people, and keeping passion alive.""",
|
32 |
+
"""
|
33 |
+
A: So Barry. It was good to talk to you. Thanks very much for phoning.
|
34 |
+
B: My pleasure. By the way, how's your golf these days? Still playing?
|
35 |
+
A: No, not much. I just don't seem to find the time these days. Anyway, Barry ...
|
36 |
+
B: What a shame! You used to enjoy it so much.
|
37 |
+
A: It's true. Right Barry. I must fly. I'm late for a meeting.
|
38 |
+
B: OK. I don't want to keep you. So, you'll give me a ring when you're back, right?
|
39 |
+
A: I certainly will. And you'll email me a copy of the report?
|
40 |
+
B: It'll be with you first thing tomorrow.
|
41 |
+
A: That's great Barry. Have a good weekend!
|
42 |
+
B: Same to you too! Bye, Andy."""]
|
43 |
+
)
|
44 |
+
|
45 |
+
iface.launch()
|