Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def send_dummy_request(space_url):
|
7 |
-
try:
|
8 |
-
response = requests.get(space_url)
|
9 |
-
# Print the response status code (optional)
|
10 |
-
print(f"Response Status Code Of Wait: {response.status_code}")
|
11 |
-
except Exception as e:
|
12 |
-
print(f"Error: {e}")
|
13 |
-
|
14 |
-
def send_dummy_request_self(space_url_self):
|
15 |
-
try:
|
16 |
-
response = requests.get(space_url_self)
|
17 |
-
# Print the response status code (optional)
|
18 |
-
print(f"Response Status Code Of Self: {response.status_code}")
|
19 |
-
except Exception as e:
|
20 |
-
print(f"Error: {e}")
|
21 |
-
|
22 |
-
def background_request(space_url,space_url_self, interval_seconds):
|
23 |
-
try:
|
24 |
-
while True:
|
25 |
-
send_dummy_request(space_url)
|
26 |
-
send_dummy_request_self(space_url_self)
|
27 |
-
time.sleep(interval_seconds)
|
28 |
-
except KeyboardInterrupt:
|
29 |
-
print("Background script terminated by user.")
|
30 |
-
|
31 |
-
# Replace 'YOUR_SPACE_URL' with the actual URL of your deployed Hugging Face Space
|
32 |
-
space_url = 'https://huggingface.co/spaces/clone3/Wait'
|
33 |
-
space_url_self = 'https://huggingface.co/spaces/clone3/Sender'
|
34 |
-
|
35 |
-
# Set the interval for sending requests (in seconds)
|
36 |
-
interval_seconds = 1800 # 30 minutes
|
37 |
-
|
38 |
-
# Start the background thread
|
39 |
-
background_thread = threading.Thread(target=background_request, args=(space_url,space_url_self, interval_seconds))
|
40 |
-
background_thread.start()
|
41 |
-
|
42 |
-
# Gradio interface
|
43 |
-
def echo_text(text):
|
44 |
-
return f"You said: {text}"
|
45 |
-
|
46 |
-
iface = gr.Interface(fn=echo_text, inputs="text", outputs="text")
|
47 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import websockets
|
3 |
+
import asyncio
|
4 |
+
|
5 |
+
async def send_to_websocket(message):
|
6 |
+
uri = "ws://localhost:8765" # Replace with your WebSocket server URI
|
7 |
+
async with websockets.connect(uri) as websocket:
|
8 |
+
await websocket.send(message)
|
9 |
+
response = await websocket.recv()
|
10 |
+
return response
|
11 |
+
|
12 |
+
def predict(input_text):
|
13 |
+
# You can replace this with your actual machine learning model prediction logic
|
14 |
+
# For now, we'll just send the input to the WebSocket server and echo the response
|
15 |
+
response = asyncio.run(send_to_websocket(input_text))
|
16 |
+
return response
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=predict,
|
20 |
+
inputs=gr.Textbox(),
|
21 |
+
outputs="text",
|
22 |
+
live=True,
|
23 |
+
)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
iface.launch()
|