File size: 844 Bytes
8cd2c47
 
abd5804
 
8cd2c47
 
 
 
 
 
 
 
 
abd5804
 
 
 
8cd2c47
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()