File size: 1,772 Bytes
e615cdd
 
 
 
eb2e5c8
ae3d83e
b6a293b
eb2e5c8
 
 
 
e615cdd
ae3d83e
 
b6a293b
 
 
 
 
 
ae3d83e
e615cdd
a8dedcf
e615cdd
 
 
 
 
 
edd5b42
eb2e5c8
b105cdd
e615cdd
edd5b42
 
 
 
 
 
 
 
a8dedcf
eb2e5c8
edd5b42
 
a8dedcf
ae3d83e
 
edd5b42
a8dedcf
 
e615cdd
 
 
 
 
 
 
a8dedcf
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
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
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
from datetime import datetime
import math
from gradio_client import Client

def log_message(message):
    # Print message with a timestamp
    print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {message}")


def useless_computation():
    client = Client("bluuebunny/update_arxiv_embeddings")
    result = client.predict(
    		name="Hello!!",
    		api_name="/predict"
    )
    print(result)

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

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

    while True:

        current_day = datetime.now().weekday()  # Monday is 0, Sunday is 6

        if current_day == 0:  # Check if today is Monday

            log_message("Starting Updation")
    
            # Run run.py as a subprocess
            subprocess.run(["python", "update_embeddings.py"])  # Use "python3" if needed
    
            log_message("Finished Updation")
    
            # Wait for the specified interval before running again
            time.sleep(60 * 60 * 24)

        else:

            print("Today is not Monday, lets check again in some.")

            useless_computation()
            
            # Wait a bit
            time.sleep(60 * 60 * 1)  

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


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

# Start the thread
script_thread.start()

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