164_App / app.py
mlope48's picture
Update app.py
391c910 verified
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)