Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import websockets
|
|
|
|
| 3 |
|
| 4 |
async def send_wss_request():
|
| 5 |
uri = "wss://clone3-imagex-clone-advance.hf.space/queue/join"
|
|
@@ -11,59 +13,25 @@ async def send_wss_request():
|
|
| 11 |
# Receive the response
|
| 12 |
response = await websocket.recv()
|
| 13 |
print(f"Received: {response}")
|
| 14 |
-
|
| 15 |
-
# Send a message
|
| 16 |
-
message = '{"fn_index":2,"session_hash":"kb46puzhzr"}'
|
| 17 |
-
await websocket.send(message)
|
| 18 |
-
print(f"Sent: {message}")
|
| 19 |
-
|
| 20 |
-
# Receive the response
|
| 21 |
-
response = await websocket.recv()
|
| 22 |
-
print(f"Received: {response}")
|
| 23 |
-
|
| 24 |
-
# Receive the response
|
| 25 |
-
response = await websocket.recv()
|
| 26 |
-
print(f"Received: {response}")
|
| 27 |
-
|
| 28 |
-
message='{"data":["spiderman",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
|
| 29 |
-
await websocket.send(message)
|
| 30 |
-
print(f"Sent: {message}")
|
| 31 |
-
|
| 32 |
-
# Receive the response
|
| 33 |
-
response = await websocket.recv()
|
| 34 |
-
print(f"Received: {response}")
|
| 35 |
-
|
| 36 |
|
| 37 |
async with websockets.connect(uri2) as websocket:
|
| 38 |
# Receive the response
|
| 39 |
response = await websocket.recv()
|
| 40 |
print(f"Received: {response}")
|
| 41 |
|
| 42 |
-
# Send a message
|
| 43 |
-
message = '{"fn_index":2,"session_hash":"kb46puzhzr"}'
|
| 44 |
-
await websocket.send(message)
|
| 45 |
-
print(f"Sent: {message}")
|
| 46 |
-
|
| 47 |
-
# Receive the response
|
| 48 |
-
response = await websocket.recv()
|
| 49 |
-
print(f"Received: {response}")
|
| 50 |
-
|
| 51 |
-
# Receive the response
|
| 52 |
-
response = await websocket.recv()
|
| 53 |
-
print(f"Received: {response}")
|
| 54 |
-
|
| 55 |
-
message='{"data":["spiderman",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
|
| 56 |
-
await websocket.send(message)
|
| 57 |
-
print(f"Sent: {message}")
|
| 58 |
-
|
| 59 |
-
# Receive the response
|
| 60 |
-
response = await websocket.recv()
|
| 61 |
-
print(f"Received: {response}")
|
| 62 |
-
|
| 63 |
except websockets.exceptions.ConnectionClosed:
|
| 64 |
print("Connection closed. Reconnecting in 30 minutes.")
|
| 65 |
|
| 66 |
# Sleep for 30 minutes before the next iteration
|
| 67 |
await asyncio.sleep(30 * 60)
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import asyncio
|
| 3 |
import websockets
|
| 4 |
+
import threading
|
| 5 |
|
| 6 |
async def send_wss_request():
|
| 7 |
uri = "wss://clone3-imagex-clone-advance.hf.space/queue/join"
|
|
|
|
| 13 |
# Receive the response
|
| 14 |
response = await websocket.recv()
|
| 15 |
print(f"Received: {response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
async with websockets.connect(uri2) as websocket:
|
| 18 |
# Receive the response
|
| 19 |
response = await websocket.recv()
|
| 20 |
print(f"Received: {response}")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except websockets.exceptions.ConnectionClosed:
|
| 23 |
print("Connection closed. Reconnecting in 30 minutes.")
|
| 24 |
|
| 25 |
# Sleep for 30 minutes before the next iteration
|
| 26 |
await asyncio.sleep(30 * 60)
|
| 27 |
|
| 28 |
+
def run_websocket():
|
| 29 |
+
asyncio.get_event_loop().run_until_complete(send_wss_request())
|
| 30 |
+
|
| 31 |
+
# Create a thread for the WebSocket function
|
| 32 |
+
websocket_thread = threading.Thread(target=run_websocket)
|
| 33 |
+
websocket_thread.start()
|
| 34 |
+
|
| 35 |
+
# Define your Gradio interface here
|
| 36 |
+
iface = gr.Interface(fn=None, live=True)
|
| 37 |
+
iface.launch()
|