updated code
Browse files
app.py
CHANGED
@@ -1,20 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
# API endpoint
|
5 |
API_URL = "https://api-inference.huggingface.co/models/Rahmat82/fastSUMMARIZER-t5-small-finetuned-on-xsum"
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return "Error occurred. Please try again."
|
18 |
|
19 |
iface = gr.Interface(
|
20 |
theme=gr.themes.Soft(),
|
@@ -36,4 +76,4 @@ iface = gr.Interface(
|
|
36 |
]
|
37 |
)
|
38 |
|
39 |
-
iface.launch()
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import requests
|
3 |
+
|
4 |
+
# # API endpoint
|
5 |
+
# API_URL = "https://api-inference.huggingface.co/models/Rahmat82/fastSUMMARIZER-t5-small-finetuned-on-xsum"
|
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]["summary_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 slower here 🐢 </b><h3>On GPU/CPU it takes <1s 🚀</h4> <h3>Please keep in mind that the input text should be at least few sentences long 🙂</h4>" ,
|
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 |
+
# There will soon be flying taxis. Many of us grew up watching science fiction movies with these. The Japanese airline ANA and a U.S. tech start-up called Joby Aviation will fly air taxis at the 2025 World Expo in Osaka. They are currently building the taxis. They will need to follow air traffic rules. They will also need to train flying taxi pilots. The five-seat, all-electric taxi will take off and land vertically. It will fly as far as 241 kilometers and have a top speed of 321kph. Joby said the taxis are environmentally friendly. People can reduce their carbon footprint. It said Japan was a great place to test the taxis because 92 per cent of the population live in towns and cities. The president of ANA said the airline has 70 years of safe and reliable flights. He said it was good that customers have "the option to travel rapidly, and sustainably, from an international airport to a downtown location".
|
32 |
+
# """],
|
33 |
+
# ["""
|
34 |
+
# Everybody knows that eating carrots is good for our eyesight. A new study suggests that grapes are also good for our eyes. Researchers from the National University of Singapore have found that eating just a few grapes a day can improve our vision. This is especially so for people who are older. Dr Eun Kim, the lead researcher, said: "Our study is the first to show that grape consumption beneficially impacts eye health in humans, which is very exciting, especially with a growing, ageing population." Dr Kim added that, "grapes are an easily accessible fruit that studies have shown can have a beneficial impact" on our eyesight. This is good news for people who don't really like carrots. The study is published in the journal "Food & Function". Thirty-four adults took part in a series of experiments over 16 weeks. Half of the participants ate one-and-a-half cups of grapes per day; the other half ate a placebo snack. Dr Kim did not tell the participants or the researchers whether she was testing the grapes or the snack. She thought that not revealing this information would give better test results. She found that people who ate the grapes had improved muscle strength around the retina. The retina passes information about light to the brain via electrical signals. It protects the eyes from damaging blue light. A lot of blue light comes from computer and smartphone screens, and from LED lights.
|
35 |
+
# """]
|
36 |
+
# ]
|
37 |
+
# )
|
38 |
+
|
39 |
+
# iface.launch()
|
40 |
+
|
41 |
import gradio as gr
|
42 |
+
import aiohttp
|
43 |
+
import asyncio
|
44 |
+
import os
|
45 |
|
46 |
# API endpoint
|
47 |
API_URL = "https://api-inference.huggingface.co/models/Rahmat82/fastSUMMARIZER-t5-small-finetuned-on-xsum"
|
|
|
48 |
SECRET_KEY = os.environ.get("summarizer")
|
49 |
|
50 |
+
async def summarize(text):
|
51 |
headers = {"Authorization": f"Bearer {SECRET_KEY}"}
|
52 |
data = {"inputs": text}
|
53 |
+
async with aiohttp.ClientSession() as session:
|
54 |
+
async with session.post(API_URL, headers=headers, json=data) as response:
|
55 |
+
response.raise_for_status() # Raise exception for non-200 status codes
|
56 |
+
result = await response.json()
|
57 |
+
return result[0]["summary_text"]
|
|
|
58 |
|
59 |
iface = gr.Interface(
|
60 |
theme=gr.themes.Soft(),
|
|
|
76 |
]
|
77 |
)
|
78 |
|
79 |
+
iface.launch()
|