File size: 1,043 Bytes
e615cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess # Run update_embeddings.py as subprocess
import time # Run update_embeddings.py periodically
import threading # in a separate thread
import gradio as gr # Create a Gradio interface so spaces doesnt timeout

# Function to run update_embeddings.py periodically
def run_script_periodically(interval):

    # Wait for the Gradio server to start
    time.sleep(10)

    while True:

        # Run run.py as a subprocess
        subprocess.run(["python", "update_embeddings.py"])  # Use "python3" if needed

        # Wait for the specified interval before running again
        time.sleep(interval)

# Function to greet the user
def greet(name):
    return "Hello " + name + "!!"

# Specify the interval (in seconds)
interval_seconds = 60*60*24*1  # Run run.py every day

# Create a thread to run the script periodically
script_thread = threading.Thread(target=run_script_periodically, args=(interval_seconds,))

# Start the thread
script_thread.start()

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()