File size: 1,540 Bytes
2d19da0 ef3f85d 2d19da0 391c910 2d19da0 391c910 2d19da0 391c910 2d19da0 391c910 2d19da0 391c910 2d19da0 b4d82cb |
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 |
import gradio as gr
from huggingface_hub import InferenceClient
def saveData(prompt):
import csv
with open('/content/drive/MyDrive/IT 164/prompt.csv', 'a') as f:
w=csv.writer(f)
w.writerow([prompt])
def fill_mask(prompt):
client=InferenceClient()
input= f"{prompt} <mask>"
output=client.fill_mask(input)
allsentences=''
for item in output:
mask=item.token_str
if mask=='': break
sentence=f"{prompt} {mask}"
allsentences=allsentences+sentence+'\n'
return (allsentences)
def fill_mask_bert(prompt):
model_name="FacebookAI/xlm-roberta-base"
client=InferenceClient(model_name)
input= f"{prompt} <mask>"
output=client.fill_mask(input)
allsentences=''
for item in output:
mask=item.token_str
if mask=='': break
sentence=f"{prompt} {mask}"
allsentences=allsentences+sentence+'\n'
return (allsentences)
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
with gr.Row():
with gr.Column():
prompt=gr.Textbox(label="your prompt",scale=1)
with gr.Column():
blackforest_btn=gr.Button("fill mask", scale=1)
text= gr.Text(type="text", label="fill word")
#sending the prompt to function to get a text
blackforest_btn.click(fn=fill_mask, inputs=prompt, outputs=text)
with gr.Column():
bert_btn=gr.Button("fill mask", scale=1)
berttext= gr.Text(type="text", label="fill word")
#sending the prompt to function to get a text
bert_btn.click(fn=fill_mask_bert, inputs=prompt, outputs=berttext)
demo.launch(debug=True) |