|
|
import gradio as gr |
|
|
from gradio_client import Client |
|
|
import re |
|
|
import os |
|
|
|
|
|
def escape_special_characters(result): |
|
|
|
|
|
result_str = str(result) |
|
|
|
|
|
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() |
|
|
|