sentence_fix / app.py
taufiqdp's picture
Create app.py
699f33d
raw
history blame
1.04 kB
import gradio as gr
import google.generativeai as palm
import os
api_key = os.environ("api_key")
palm.configure(api_key=api_key)
defaults = {
'model': 'models/text-bison-001',
'temperature': 0.7,
'candidate_count': 1,
'top_k': 40,
'top_p': 0.95,
'max_output_tokens': 1024,
'stop_sequences': [],
'safety_settings': [{"category":"HARM_CATEGORY_DEROGATORY","threshold":3},{"category":"HARM_CATEGORY_TOXICITY","threshold":3},{"category":"HARM_CATEGORY_VIOLENCE","threshold":3},{"category":"HARM_CATEGORY_SEXUAL","threshold":3},{"category":"HARM_CATEGORY_MEDICAL","threshold":3},{"category":"HARM_CATEGORY_DANGEROUS","threshold":3}]
}
def chat(Sentences):
response = palm.generate_text(
**defaults,
prompt=f"""Correct this sentences and correct the grammar. Do not add the quotation marks on your correction sentences: '{Sentences}'"""
)
return response.result
demo = gr.Interface(fn=chat, inputs=gr.Textbox(lines=10), outputs=gr.Textbox(lines=10), allow_flagging="never")
demo.launch(debug=True)