aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-11-12 07:55:03 +0000
committerterminaldweller <thabogre@gmail.com>2021-11-12 07:55:03 +0000
commit6cf47267ce344d38997f5d66ef840b182940d5af (patch)
treec394f7cda5bbcf74dbf0eca0b5f60608f33ad59e
parentthe server is up and running now. the things that worked before work now (diff)
downloaddevourer-6cf47267ce344d38997f5d66ef840b182940d5af.tar.gz
devourer-6cf47267ce344d38997f5d66ef840b182940d5af.zip
added health endpoint
Diffstat (limited to '')
-rw-r--r--devourer.py51
-rwxr-xr-xtests.sh4
2 files changed, 35 insertions, 20 deletions
diff --git a/devourer.py b/devourer.py
index 4fb8532..8532bf3 100644
--- a/devourer.py
+++ b/devourer.py
@@ -127,7 +127,6 @@ def extractRequirements(textBody: str) -> list:
"can",
"cannot",
]
- nltk.download("punkt")
sentences = nltk.sent_tokenize(textBody)
for sentence in sentences:
for keyword in REQ_KEYWORDS:
@@ -160,15 +159,12 @@ def summarizeText(text: str) -> str:
def textToAudio(text: str) -> str:
"""Transform the given text into audio."""
+ path = str()
try:
- path = str()
- path = (
- os.environ["AUDIO_DUMP_DIR"]
- + time.today().strftime("%b-%d-%Y-%M-%S-%f")
- + ".mp3"
- )
+ time_str = time.today().strftime("%b-%d-%Y-%M-%S-%f")
tts = gTTS(text)
- tts.save(path)
+ tts.save(os.environ["AUDIO_DUMP_DIR"] + "/" + time_str + ".mp3")
+ path = os.environ["AUDIO_DUMP_DIR"] + "/" + time_str + ".mp3"
except Exception as e:
logging.exception(e)
finally:
@@ -199,6 +195,7 @@ def getRequirements(url: str, sourcetype: str) -> list:
return result
+# FIXME-summary=bart doesnt work
def summarizeLinkToAudio(url, summary) -> str:
"""Summarizes the text inside a given url into audio."""
result = str()
@@ -221,6 +218,7 @@ def summarizeLinkToAudio(url, summary) -> str:
return result
+# FIXME-change my name
def summarizeLinksToAudio(url, summary) -> None:
"""Summarize a list of urls into audio files."""
results = list()
@@ -269,9 +267,10 @@ def getAudioFromFile(audio_path: str) -> str:
app = FastAPI()
+nltk.download("punkt")
-@app.get("/tika")
+@app.get("/mila/tika")
async def pdf_to_audio_ep(url: str):
"""turns a pdf into an audiofile"""
audio_path = pdfToVoice()
@@ -282,7 +281,7 @@ async def pdf_to_audio_ep(url: str):
}
-@app.get("/reqs")
+@app.get("/mila/reqs")
async def extract_reqs_ep(url: str, sourcetype: str = "html"):
"""extracts the requirements from a given url"""
result = getRequirements()
@@ -293,7 +292,7 @@ async def extract_reqs_ep(url: str, sourcetype: str = "html"):
}
-@app.get("/wiki")
+@app.get("/mila/wiki")
async def wiki_search_ep(term: str, audio: bool = False):
"""search and summarizes from wikipedia"""
text = searchWikipedia(term)
@@ -315,34 +314,36 @@ async def wiki_search_ep(term: str, audio: bool = False):
}
-@app.get("/summ")
+@app.get("/mila/summ")
async def summarize_ep(url: str, summary: str = "none", audio: bool = False):
"""summarize and turn the summary into audio"""
text = summarizeLinkToAudio(url, summary)
if audio:
audio_path = textToAudio(text)
+ print(audio_path)
return {
- "Content-Type": "application/json",
- "isOK": (True if audio_path != "" else False)
- and (True if text != "" else False),
+ "Content-Type": "audio/mpeg",
+ # "isOK": (True if audio_path != "" else False)
+ # and (True if text != "" else False),
"audio": getAudioFromFile(audio_path) if audio_path != "" else "",
- "text": text,
+ # "text": text,
}
else:
return {
"Content-Type": "application/json",
"isOK": True if text != "" else False,
- "audio": "",
+ # "audio": "",
"text": text,
}
-@app.get("/mila")
+@app.get("/mila/mila")
async def mila_ep(url: str, summary: str = "newspaper", audio: bool = False):
"""extract all the urls and then summarize and turn into audio"""
text = summarizeLinksToAudio(url, summary)
if audio:
audio_path = textToAudio(text)
+ print(audio_path)
return {
"Content-Type": "application/json",
"isOK": (True if audio_path != "" else False)
@@ -357,3 +358,17 @@ async def mila_ep(url: str, summary: str = "newspaper", audio: bool = False):
"audio": "",
"text": text,
}
+
+
+@app.get("/mila/health")
+async def health_ep():
+ return {"isOK": True}
+
+
+@app.get("/mila/robots.txt")
+async def robots_ep():
+ return {
+ "Content-Type": "apllication/json",
+ "User-Agents": "*",
+ "Disallow": "/",
+ }
diff --git a/tests.sh b/tests.sh
index c88fb90..4e895b6 100755
--- a/tests.sh
+++ b/tests.sh
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
-curl -k -X GET https://localhost:19019/summ?url=https://dilipkumar.medium.com/standalone-mongodb-on-kubernetes-cluster-19e7b5896b27&summary=none&audio=false
-curl -k -X GET https://localhost:19019/wiki?term=iommu
+curl -k -X GET https://localhost:19019/mila/summ?url=https://dilipkumar.medium.com/standalone-mongodb-on-kubernetes-cluster-19e7b5896b27&summary=newspaper&audio=false
+curl -k -X GET https://localhost:19019/mila/wiki?term=iommu