Rahmat82 commited on
Commit
b131941
·
verified ·
1 Parent(s): f1de923

input validation

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import aiohttp
3
  import asyncio
4
  import os
 
5
 
6
  # API endpoint - model name
7
  API_URL = "https://api-inference.huggingface.co/models/Rahmat82/t5-small-finetuned-summarization-xsum"
@@ -9,7 +10,7 @@ SECRET_KEY = os.environ.get("summarizer")
9
 
10
  # asynchronous function
11
  async def summarize(text, retries=3):
12
- if len(text) < 75:
13
  return "<span style='color: red;'>Error: Input should contain more than a few sentences.</span>"
14
  headers = {"Authorization": f"Bearer {SECRET_KEY}"}
15
  data = {
 
2
  import aiohttp
3
  import asyncio
4
  import os
5
+ import re
6
 
7
  # API endpoint - model name
8
  API_URL = "https://api-inference.huggingface.co/models/Rahmat82/t5-small-finetuned-summarization-xsum"
 
10
 
11
  # asynchronous function
12
  async def summarize(text, retries=3):
13
+ if len(re.findall(r'[.!?]+', text)) < 3:
14
  return "<span style='color: red;'>Error: Input should contain more than a few sentences.</span>"
15
  headers = {"Authorization": f"Bearer {SECRET_KEY}"}
16
  data = {