Spaces:
Sleeping
Sleeping
File size: 2,060 Bytes
3dcceab 34cbe39 3dcceab 34cbe39 3dcceab 34cbe39 3dcceab 2fbe11e 3dcceab 34cbe39 7295275 3dcceab bfd8132 3dcceab 83ebe3c 3dcceab 83ebe3c 3dcceab 83ebe3c 3dcceab 83ebe3c 3dcceab 83ebe3c 3dcceab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import os
import shutil
import gradio as gr
from uuid import uuid4
from requests import Session
import urllib.parse
API_URL = os.environ.get('API_URL')
API_TOKEN = os.environ.get('API_TOKEN')
class Client:
def __init__(self):
self.c = Session()
self.c.headers.update({
'Content-Type': 'application/json',
'Authorization': f'Bearer {API_TOKEN}'
})
def send_message(self, input):
res = self.c.post(
API_URL,
json={'message': {'text': input}}
)
return res.json()
def send_images(self, text, images):
res = self.c.post(
API_URL,
json={'message': {'file': images, 'text': text}}
)
return res.json()
client = Client()
def send_message(input, files):
print('sending message', files)
res = client.send_images(input, files)
print(res)
return res['message']['data']
def upload_files(files):
if not os.path.exists('uploads'):
os.makedirs('uploads')
print('uploading files', files)
file_urls = []
for file in files:
file_urls.append(
f'https://philipp-zettl-easybits-fal-lora.hf.space/gradio_api/file={urllib.parse.quote_plus(file)}'
)
print(file_urls)
return file_urls
with gr.Blocks() as demo:
gr.Markdown("## Demo")
with gr.Row(equal_height=True):
with gr.Column():
gr.Markdown("### Input")
inpt = gr.Textbox(label="LoRA Key-Word")
upload_button = gr.UploadButton("Upload Images", file_count='multiple', file_types=['image'])
hidden_files = gr.State([])
upload_button.upload(upload_files, upload_button, hidden_files)
with gr.Column():
gr.Markdown("### Output")
output = gr.Textbox(lines=5, label="Output Text")
with gr.Row():
send_button = gr.Button("Send")
send_button.click(send_message, inputs=[inpt, hidden_files], outputs=[output])
demo.launch(share=True, allowed_paths=['uploads/*'])
|