Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
log_file = "out-file.txt" | |
def run(): | |
import subprocess | |
import sys | |
with open("out-file.txt", "w") as f: | |
process = subprocess.Popen( | |
[f"{sys.executable}", "prometheus_pipeline.py"], | |
stdout=subprocess.PIPE, | |
) | |
content = "" | |
for line in iter(process.stdout.readline, ""): | |
content = content.split("\n") | |
content.append(line.decode("utf-8")) | |
content = content[-10:] | |
content = "\n".join(content) | |
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() | |