Spaces:
Paused
Paused
File size: 1,460 Bytes
699f33d 6489fa9 699f33d 2234f95 699f33d cd0d71a 699f33d 2234f95 699f33d 2234f95 699f33d 2234f95 |
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 |
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(text):
response = palm.generate_text(
**defaults,
prompt=f"""Please correct these sentences and rectify any grammar errors.
Additionally, when making your corrections, kindly refrain from including quotation marks in your revised sentences.
The objective is to enhance the overall clarity and coherence of the paragraph.
Sentences: {text}"""
)
return response.result
app = gr.Interface(fn=chat,
inputs=gr.Textbox(lines=10, label="Text", max_lines=10),
outputs=gr.Textbox(lines=10, label="Output", max_lines=10, show_copy_button=True),
allow_flagging="never")
if __name__ == "__main__":
app.launch(debug=True) |