WebsoketSend / app.py
clone3's picture
Update app.py
bc3aeb9
raw
history blame
714 Bytes
import gradio as gr
import websockets
import asyncio
async def send_to_websocket(message):
uri = "ws://localhost:8765" # Replace with your WebSocket server URI
async with websockets.connect(uri) as websocket:
await websocket.send(message)
response = await websocket.recv()
return response
def predict(input_text):
# You can replace this with your actual machine learning model prediction logic
# For now, we'll just send the input to the WebSocket server and echo the response
response = asyncio.run(send_to_websocket(input_text))
return response
iface = gr.Interface(
fn=predict,
inputs=gr.Textbox(),
outputs="text",
live=True,
)
iface.launch()