Spaces:
Sleeping
Sleeping
File size: 1,078 Bytes
e298c65 c838896 b693829 e36e778 c838896 e36e778 e298c65 e36e778 d3d5007 e36e778 8e226e6 e298c65 e36e778 c838896 e36e778 c838896 e36e778 c838896 e36e778 b693829 |
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 |
import spaces
import os
import gradio as gr
log_file = "out-file.txt"
@spaces.GPU(duration=120)
def run():
import subprocess
import sys
process = subprocess.Popen(
[f"{sys.executable}", "prometheus_pipeline.py"],
stdout=subprocess.PIPE,
)
content = ""
for line in iter(process.stdout.readline, ""):
content += line.decode("utf-8") + "\n"
yield content
def hello(profile: gr.OAuthProfile | None) -> str:
if profile is None:
return "I don't know you."
return f"Hello {profile.name}"
def set_token(oauth_token: gr.OAuthToken | None) -> str:
if oauth_token is None:
return "Please log in."
os.environ["HF_TOKEN"] = oauth_token.token
with gr.Blocks() as demo:
gr.LoginButton()
m1 = gr.Markdown()
m2 = gr.Markdown()
demo.load(hello, inputs=None, outputs=m1)
demo.load(set_token, inputs=None, outputs=m2)
button = gr.Button("Run pipeline")
output = gr.Code(label="Terminal output", interactive=False)
button.click(run, outputs=output)
demo.launch()
|