Skip to content

Commit c19381f

Browse files
committed
created fastAPI webserver
1 parent 62aba65 commit c19381f

File tree

7 files changed

+41
-5
lines changed

7 files changed

+41
-5
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ SWE Project :
3535
3636
> Created a new function to search in wikipedia by name.
3737
38+
> Created a webservice using Fastapi and created api endpoints. Written test cases for FastAPI endpoints.
39+
40+
> Created a new NLP function in script. To find the phrases
3841

__pycache__/main.cpython-312.pyc

790 Bytes
Binary file not shown.

main.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
from mylib.script import wiki
1+
from fastapi import FastAPI
2+
from mylib.script import wiki, search_wiki, phrase
3+
import uvicorn
24

3-
result = wiki()
45

5-
print(result)
6+
app = FastAPI()
7+
8+
@app.get("/")
9+
def read_root():
10+
return {"message": "Wikipedia API. Call /search or /find-wiki"}
11+
12+
13+
@app.get("/search/{name}")
14+
def search_wikipedia(name: str):
15+
result = search_wiki(name)
16+
return {"result": result}
17+
18+
@app.get("/find-wiki/{value}")
19+
def my_wiki(value: str):
20+
result = wiki(value)
21+
return {"result": result}
22+
23+
@app.get("/phrases/{value}")
24+
def phrases(value: str):
25+
result = phrase(value)
26+
return {"result": result}
27+
28+
29+
if __name__ == "__main__":
30+
uvicorn.run(app, port= 8080, host='0.0.0.0')
276 Bytes
Binary file not shown.

mylib/script.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import wikipedia
2-
2+
from textblob import TextBlob
33

44
def wiki(name="War Goddess", length=1):
55
"""wikipedia data fetcher"""
@@ -11,4 +11,9 @@ def search_wiki(name):
1111
result = wikipedia.search(name)
1212
return result
1313

14+
def phrase(name):
15+
result = wiki(name)
16+
blob = TextBlob(result)
17+
return blob.noun_phrases
18+
1419
# print(search_wiki("barack"))

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ pytest==8.3.5
33
pytest-cov==6.0.0
44
pylint==3.3.5
55
black==25.1.0
6-
fire==0.7.0
6+
fire==0.7.0
7+
fastapi==0.115.11
8+
uvicorn==0.34.0
9+
textblob==0.19.0

test_main.py

Whitespace-only changes.

0 commit comments

Comments
 (0)