Spaces:
Sleeping
Sleeping
File size: 3,010 Bytes
dece3d8 5fa74cc dece3d8 bc3aeb9 5fa74cc d113efb fdc4ca8 ec48066 e00660b f01ed13 e00660b 02e7b61 f01ed13 fdc4ca8 f01ed13 fdc4ca8 f01ed13 fa03655 e00660b fdc4ca8 e00660b dece3d8 e3ab212 dece3d8 75ddb00 |
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 80 81 82 83 84 85 86 87 88 89 |
import gradio as gr
import asyncio
import websockets
import threading
async def send_wss_request():
uri = "wss://clone3-imagex-clone-advance.hf.space/queue/join"
uri2 = "wss://clone3-websoketsend.hf.space/queue/join"
while True:
try:
async with websockets.connect(uri) as websocket:
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Send a message
message = '{"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
message='{"data":["spiderman",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
async with websockets.connect(uri2) as websocket:
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Send a message
message = '{"fn_index":0,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
message='{"data":["spider"],"event_data":null,"fn_index":0,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
except websockets.exceptions.ConnectionClosed:
print("Connection closed. Reconnecting in 30 minutes.")
# Sleep for 30 minutes before the next iteration
await asyncio.sleep(30 * 60)
def run_websocket():
# Create a new event loop for the thread
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(send_wss_request())
# Create a thread for the WebSocket function
websocket_thread = threading.Thread(target=run_websocket)
websocket_thread.start()
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(
fn=greet,
inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
outputs="text",
)
demo.launch() |