refactored
Browse files
app.py
CHANGED
@@ -1,41 +1,3 @@
|
|
1 |
-
|
2 |
-
# # asynchronous function
|
3 |
-
# async def summarize(text, retries=3):
|
4 |
-
# if len(text)<250:
|
5 |
-
# return "⛔ You input is too short! Please input a longer text for summarization."
|
6 |
-
# headers = {"Authorization": f"Bearer {SECRET_KEY}"}
|
7 |
-
# data = {
|
8 |
-
# "inputs": text,
|
9 |
-
# "options": {
|
10 |
-
# "max_new_tokens": 100,
|
11 |
-
# "min_length": 10,
|
12 |
-
# "max_length": 500,
|
13 |
-
# "length_penalty": 2.0,
|
14 |
-
# "num_beams": 3,
|
15 |
-
# "early_stopping": True
|
16 |
-
# }
|
17 |
-
# }
|
18 |
-
# async with aiohttp.ClientSession() as session:
|
19 |
-
# for attempt in range(retries):
|
20 |
-
# try:
|
21 |
-
# async with session.post(API_URL, headers=headers, json=data) as response:
|
22 |
-
# # raise exception for non-200 status codes
|
23 |
-
# response.raise_for_status()
|
24 |
-
# result = await response.json()
|
25 |
-
# return result[0]["summary_text"]
|
26 |
-
# except aiohttp.ClientResponseError as e:
|
27 |
-
# # retry only if the error is 503 (Service Unavailable)
|
28 |
-
# if e.status == 503 and attempt < retries - 1:
|
29 |
-
# # print(f"Retry attempt {attempt+1} for 503 error.")
|
30 |
-
# # add a short delay before retrying
|
31 |
-
# await asyncio.sleep(1)
|
32 |
-
# continue
|
33 |
-
# else:
|
34 |
-
# return "Oops! 🙈 It looks like those mischievous monkeys🐒 might be swinging around the server, causing a bit of chaos with the cables. Please try it again!"
|
35 |
-
# # return f"Error: {e.status}, message='{e.message}'. Please try again 🔁"
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
import gradio as gr
|
40 |
import aiohttp
|
41 |
import asyncio
|
@@ -78,8 +40,6 @@ async def summarize(text, retries=3):
|
|
78 |
else:
|
79 |
return "Oops! 🙈 It looks like those mischievous monkeys🐒 might be swinging around the server, causing a bit of chaos with the cables. Please try it again!"
|
80 |
|
81 |
-
|
82 |
-
|
83 |
# define gradio interface
|
84 |
iface = gr.Interface(
|
85 |
theme=gr.themes.Soft(),
|
@@ -165,4 +125,42 @@ iface.launch()
|
|
165 |
# ]
|
166 |
# )
|
167 |
|
168 |
-
# iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import aiohttp
|
3 |
import asyncio
|
|
|
40 |
else:
|
41 |
return "Oops! 🙈 It looks like those mischievous monkeys🐒 might be swinging around the server, causing a bit of chaos with the cables. Please try it again!"
|
42 |
|
|
|
|
|
43 |
# define gradio interface
|
44 |
iface = gr.Interface(
|
45 |
theme=gr.themes.Soft(),
|
|
|
125 |
# ]
|
126 |
# )
|
127 |
|
128 |
+
# iface.launch()
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
# -------------------------------------------------------------------------------------------
|
133 |
+
# # asynchronous function
|
134 |
+
# async def summarize(text, retries=3):
|
135 |
+
# if len(text)<250:
|
136 |
+
# return "⛔ You input is too short! Please input a longer text for summarization."
|
137 |
+
# headers = {"Authorization": f"Bearer {SECRET_KEY}"}
|
138 |
+
# data = {
|
139 |
+
# "inputs": text,
|
140 |
+
# "options": {
|
141 |
+
# "max_new_tokens": 100,
|
142 |
+
# "min_length": 10,
|
143 |
+
# "max_length": 500,
|
144 |
+
# "length_penalty": 2.0,
|
145 |
+
# "num_beams": 3,
|
146 |
+
# "early_stopping": True
|
147 |
+
# }
|
148 |
+
# }
|
149 |
+
# async with aiohttp.ClientSession() as session:
|
150 |
+
# for attempt in range(retries):
|
151 |
+
# try:
|
152 |
+
# async with session.post(API_URL, headers=headers, json=data) as response:
|
153 |
+
# # raise exception for non-200 status codes
|
154 |
+
# response.raise_for_status()
|
155 |
+
# result = await response.json()
|
156 |
+
# return result[0]["summary_text"]
|
157 |
+
# except aiohttp.ClientResponseError as e:
|
158 |
+
# # retry only if the error is 503 (Service Unavailable)
|
159 |
+
# if e.status == 503 and attempt < retries - 1:
|
160 |
+
# # print(f"Retry attempt {attempt+1} for 503 error.")
|
161 |
+
# # add a short delay before retrying
|
162 |
+
# await asyncio.sleep(1)
|
163 |
+
# continue
|
164 |
+
# else:
|
165 |
+
# return "Oops! 🙈 It looks like those mischievous monkeys🐒 might be swinging around the server, causing a bit of chaos with the cables. Please try it again!"
|
166 |
+
# # return f"Error: {e.status}, message='{e.message}'. Please try again 🔁"
|