Spaces:
Build error
Build error
File size: 1,862 Bytes
d38d726 f70ff9e d38d726 f70ff9e 3084017 d38d726 d11e70d 3084017 d38d726 d11e70d d38d726 d11e70d d38d726 3084017 d38d726 3084017 46ff5db 3084017 d38d726 46ff5db d38d726 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import os
import json
import requests
import gradio as gr
from gradio import inputs, outputs
ENDPOINT = (
"https://api-inference.huggingface.co/models/ceshine/t5-paraphrase-quora-paws"
)
def paraphrase(source_text: str, temperature: float):
if temperature > 0:
params = {
"do_sample": True,
"temperature": temperature,
"top_k": 5,
"num_return_sequences": 10,
"max_length": 100
}
else:
params = {
"num_beams": 10,
"num_return_sequences": 10,
"max_length": 100
}
res = requests.post(
ENDPOINT,
headers={"Authorization": f"Bearer {os.environ['TOKEN']}"},
data=json.dumps(
{
"inputs": "paraphrase: " + source_text,
"parameters": params,
}
),
)
if not (res.status_code == 200):
return f"Got a {res.status_code} status code from HuggingFace."
results = res.json()
# print(results)
outputs = [
x["generated_text"]
for x in results
if x["generated_text"].lower() != source_text.lower().strip()
][:3]
text = ""
for i, output in enumerate(outputs):
text += f"{i+1}: {output}\n\n"
return text
interface = gr.Interface(
fn=paraphrase,
inputs=[
inputs.Textbox(label="Source text"),
inputs.Number(default=0.0, label="Temperature (0 -> disable sampling and use beam search)"),
],
outputs=outputs.Textbox(label="Generated text:"),
title="T5 Sentence Paraphraser",
description="A paraphrasing model trained on PAWS and Quora datasets.",
examples=[
["I bought a ticket from London to New York.", 0],
["Weh Seun spends 14 hours a week doing housework.", 1.2],
],
)
interface.launch(enable_queue=True)
|