Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import shutil
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from uuid import uuid4
|
6 |
+
from requests import Session
|
7 |
+
import urllib.parse
|
8 |
+
|
9 |
+
|
10 |
+
class Client:
|
11 |
+
def __init__(self):
|
12 |
+
self.c = Session()
|
13 |
+
self.c.headers.update({
|
14 |
+
'Content-Type': 'application/json',
|
15 |
+
'Authorization': 'Bearer b86b299e-c904-4c99-9357-044a69bdb7ab'
|
16 |
+
})
|
17 |
+
|
18 |
+
def send_message(self, input):
|
19 |
+
res = self.c.post(
|
20 |
+
'https://api-controller.dev.easybits.tech/api/852',
|
21 |
+
json={'message': {'text': input}}
|
22 |
+
)
|
23 |
+
return res.json()
|
24 |
+
|
25 |
+
def send_images(self, images, text):
|
26 |
+
res = self.c.post(
|
27 |
+
'https://api-controller.dev.easybits.tech/api/852',
|
28 |
+
files={'incoming_files': images, 'text': text}
|
29 |
+
)
|
30 |
+
return res.json()
|
31 |
+
|
32 |
+
|
33 |
+
client = Client()
|
34 |
+
|
35 |
+
|
36 |
+
def send_message(input, files):
|
37 |
+
print('sending message', files)
|
38 |
+
res = client.send_images(files, input)
|
39 |
+
print(res)
|
40 |
+
return res['message']['data']
|
41 |
+
|
42 |
+
def upload_files(files):
|
43 |
+
if not os.path.exists('uploads'):
|
44 |
+
os.makedirs('uploads')
|
45 |
+
|
46 |
+
print('uploading files', files)
|
47 |
+
button = None
|
48 |
+
file_urls = []
|
49 |
+
for file in files:
|
50 |
+
file_urls.append(
|
51 |
+
f'http://localhost:7860/gradio_api/file={urllib.parse.quote_plus(file)}'
|
52 |
+
)
|
53 |
+
print(file_urls)
|
54 |
+
return file_urls, button
|
55 |
+
|
56 |
+
|
57 |
+
with gr.Blocks() as demo:
|
58 |
+
gr.Markdown("## Demo")
|
59 |
+
with gr.Row(equal_height=True):
|
60 |
+
with gr.Column():
|
61 |
+
gr.Markdown("### Input")
|
62 |
+
input = gr.Textbox(label="LoRA Key-Word")
|
63 |
+
upload_button = gr.UploadButton("Upload Images", file_count='multiple', file_types=['image'])
|
64 |
+
hidden_files = gr.State([])
|
65 |
+
download_button = gr.DownloadButton("Download", visible=False)
|
66 |
+
upload_button.upload(upload_files, upload_button, [hidden_files, download_button])
|
67 |
+
with gr.Column():
|
68 |
+
gr.Markdown("### Output")
|
69 |
+
output = gr.Textbox(lines=5, label="Output Text")
|
70 |
+
with gr.Row():
|
71 |
+
send_button = gr.Button("Send")
|
72 |
+
send_button.click(send_message, inputs=[input, hidden_files], outputs=[output])
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
demo.launch(share=True, allowed_paths=['uploads/*'])
|