Spaces:
Runtime error
Runtime error
Download app.py from JR818/Jarvis-Config: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/JR818/Jarvis-Config/resolve/main/app.py
- Command line
-
hf download hf://spaces/JR818/Jarvis-Config/app.py
-
curl -L -o app.py https://huggingface.co/spaces/JR818/Jarvis-Config/resolve/main/app.py
1.22 kB
| import os | |
| import re | |
| import gradio as gr | |
| from gradio_client import Client | |
| from datetime import datetime | |
| import time | |
| client = Client("JR818/Jarvis-Backend",hf_token=os.getenv("HF_TOKEN")) | |
| def config(urls,file,request:gr.Request): | |
| try: | |
| start = time.time() | |
| host = request.client.host | |
| origin = request.request.headers['origin'] | |
| print(f"[{datetime.now()}][{host}][{origin}] urls {urls}") | |
| pat = re.compile(r"https?://") | |
| tmp = [] | |
| for line in urls.split('\n'): | |
| line = pat.sub('',line).strip() | |
| tmp.append(line) | |
| urls = ','.join(tmp) | |
| res = client.predict(urls,api_name='/config_url') | |
| gr.Info(res) | |
| diff = int((time.time()-start)*1000.0) | |
| print(f"[{datetime.now()}][{host}][{origin}] took {diff} ms") | |
| except Exception as e: | |
| gr.Warning(f"Config failed with {e}") | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Jarvis ") | |
| with gr.Row(): | |
| urls = gr.Textbox(label='Web URLs',lines=5) | |
| file = gr.File(file_types=['.pdf']) | |
| btn = gr.Button("Configure") | |
| btn.click(config,inputs=[urls,file],outputs=None) | |
| demo.queue() | |
| if __name__ == "__main__": | |
| demo.launch(show_api=False) |