easyBulbi / app.py
Tonic's picture
Update app.py
abd5804
raw
history blame contribute delete
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()