Download app.py from Tonic/easyBulbi: direct link, hf CLI and curl.
- Browser
- Download file 844 Bytes
-
https://huggingface.co/spaces/Tonic/easyBulbi/resolve/main/app.py
- Command line
-
hf download hf://spaces/Tonic/easyBulbi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Tonic/easyBulbi/resolve/main/app.py
844 Bytes
| import gradio as gr | |
| from gradio_client import Client | |
| import re | |
| import os | |
| def escape_special_characters(result): | |
| # Convert the result to a string if it's not already | |
| result_str = str(result) | |
| # Escape all special characters | |
| result_str = re.sub(r'([.^$*+?{}[\]\\|()"])', r'\\\1', result_str) | |
| return result_str | |
| def predict(question): | |
| hf_token = os.getenv('HUGGINGFACE_TOKEN') | |
| if not hf_token: | |
| raise ValueError("Hugging Face token not found in environment variables") | |
| client = Client("https://teamtonic-bulbiplantdoctor.hf.space/--replicas/k5mwx/", hf_token=hf_token) | |
| result = client.predict(question, api_name="/predict") | |
| escaped_result = escape_special_characters(result) | |
| return escaped_result | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs="text", | |
| outputs="text" | |
| ) | |
| iface.launch() | |