File size: 2,063 Bytes
699f33d
 
 
 
d8cf423
6489fa9
699f33d
 
 
2234f95
41dbe2e
2234f95
 
 
 
 
 
 
 
 
 
 
 
699f33d
 
 
41dbe2e
 
 
b950354
 
fd5c477
086584d
 
 
 
da3a9b9
086584d
 
 
73b84e9
086584d
 
 
73b84e9
fd5c477
73b84e9
086584d
b950354
41dbe2e
 
b950354
41dbe2e
 
b950354
c80914b
 
b950354
699f33d
26cff1f
 
 
 
2234f95
26cff1f
2234f95
d903b05
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
import gradio as gr
import google.generativeai as palm
import os

# Get your own API key on https://developers.generativeai.google/products/palm
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}]

}

with open("example.txt") as f:
    example = f.read()

with gr.Blocks() as app:
    def chat(text):

        try:
            response = palm.generate_text(
            **defaults,
            prompt = f"""Rewrite the following sentence to fix the grammar issues and correct the sentence.
                    {example}
                    input: {text}
                    fixed"""
            )

            return response.result
        
        except:
            result = "I am not able to correct the sentence given. Please try again."
            
            return result
        
    with gr.Column():
        text = gr.Textbox(lines=4, label="Text", max_lines=4, placeholder="Write something awesome. It will be corrected automatically.")

    with gr.Column():
        output = gr.Textbox(lines=4, label="Output", max_lines=4, show_copy_button=True)
        
        with gr.Row():
            clr_btn = gr.ClearButton([text, output])
            btn = gr.Button("Submit", variant="primary")
            btn.click(fn=chat, inputs=text, outputs=output)

    gr.Examples(
        ["Do you ready to lose?", "He don't like vegetables", "Can I gets a glass of water?"],
        text
    )

    
if __name__ == "__main__":
    app.launch()