wldmr commited on
Commit
bb71dc0
1 Parent(s): 3f68ce3
Files changed (1) hide show
  1. app.py +55 -8
app.py CHANGED
@@ -1,10 +1,21 @@
1
- import gradio as gr
2
- from PIL import Image
3
  import os
4
  import summarizer as su
5
  import nltk
6
 
 
 
 
 
 
 
 
7
 
 
 
 
 
 
 
8
  def image_mod(rpunkt_switch, link):
9
 
10
  if len(link)==0:
@@ -40,12 +51,48 @@ def image_mod(rpunkt_switch, link):
40
 
41
  print('images',images)
42
 
43
- return html, images
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
 
 
45
 
46
- demo = gr.Interface(image_mod,
47
- [gr.Checkbox(label='Restore runctuation'), "text"] , ["html", gr.Gallery()],
48
- allow_flagging="never")
49
 
50
- if __name__ == "__main__":
51
- demo.launch()
 
 
 
1
  import os
2
  import summarizer as su
3
  import nltk
4
 
5
+ from fastapi import FastAPI
6
+ from PIL import Image
7
+ import base64
8
+ from fastapi.responses import HTMLResponse, FileResponse
9
+
10
+ app = FastAPI()
11
+
12
 
13
+ @app.get("/")
14
+ async def root():
15
+ return FileResponse(path="static/index.html", media_type="text/html")
16
+
17
+
18
+ @app.get("/tubifier")
19
  def image_mod(rpunkt_switch, link):
20
 
21
  if len(link)==0:
 
51
 
52
  print('images',images)
53
 
54
+ #return html, images
55
+ return html
56
+
57
+
58
+ @app.get("/html")
59
+ async def root():
60
+ """Basic HTML response."""
61
+ body = (
62
+ "<html>"
63
+ "<body style='padding: 10px;'>"
64
+ "<h1>Welcome to the API</h1>"
65
+ "<div>"
66
+ "Check the docs: <a href='/docs'>here</a>"
67
+ "</div>"
68
+ "</body>"
69
+ "</html>"
70
+ )
71
+
72
+ return HTMLResponse(content=body)
73
+
74
+ @app.get("/api")
75
+ async def cal_api():
76
+ images = []
77
+
78
+ with open('workdir/lion.jpg', 'rb') as open_file:
79
+ byte_content = open_file.read()
80
+ base64_bytes = base64.b64encode(byte_content)
81
+ base64_string = base64_bytes.decode('utf-8')
82
+ images.append(base64_string)
83
+
84
+ with open('workdir/cheetah.jpg', 'rb') as open_file:
85
+ byte_content = open_file.read()
86
+ base64_bytes = base64.b64encode(byte_content)
87
+ base64_string = base64_bytes.decode('utf-8')
88
+ images.append(base64_string)
89
 
90
+ #image_path='lion.jpg'
91
+ #pilim = Image.open(image_path)
92
+ #pilimrot = pilim.rotate(45)
93
+ return {"data": images}
94
 
95
+ @app.get("/items/{item_id}")
96
+ async def read_item(item_id):
97
+ return {"item_id": item_id}
98