import gradio as gr import requests import re API_URL = "https://api-inference.huggingface.co/models/potsawee/t5-large-generation-squad-QuestionAnswer" headers = {"Authorization": "Bearer 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"} def query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.json() def generate_question_answer_pairs(input_text): if input_text is None: return "Please enter a text" sentences = re.split(r'(?<=[.!?])', input_text) outputs = [] # for i in range(len(sentences)): # output = query({ # "inputs": sentences[i], # }) # outputs.append(output) for sentence in sentences: if sentence.strip(): output = query({ "inputs": sentence, }) outputs.append(output) return outputs title = "Question-Answer Pairs Generation" input_text = gr.Textbox(lines=4, label="Text:") output_text = gr.Textbox() interface = gr.Interface( fn=generate_question_answer_pairs, inputs=input_text, outputs=output_text, title=title, ) interface.launch()