taufiqdp commited on
Commit
b950354
1 Parent(s): 55b10e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -8,7 +8,7 @@ palm.configure(api_key=api_key)
8
 
9
  defaults = {
10
  'model': 'models/text-bison-001',
11
- 'temperature': 0.7,
12
  'candidate_count': 1,
13
  'top_k': 40,
14
  'top_p': 0.95,
@@ -24,21 +24,28 @@ defaults = {
24
 
25
  }
26
 
27
- def chat(text):
28
- response = palm.generate_text(
29
- **defaults,
30
- prompt=f"""Please correct these sentences and rectify any grammar errors.
31
- Additionally, when making your corrections, kindly refrain from including quotation marks in your revised sentences.
32
- The objective is to enhance the overall clarity and coherence of the paragraph.
33
- Sentences: {text}"""
34
- )
35
- return response.result
36
-
37
- app = gr.Interface(fn=chat,
38
- inputs=gr.Textbox(lines=10, label="Text", max_lines=10,
39
- placeholder="Write something amazing. It will be checked for grammar and spelling errors automatically."),
40
- outputs=gr.Textbox(lines=10, label="Output", max_lines=10, show_copy_button=True),
41
- allow_flagging="never")
 
 
 
 
 
 
 
42
 
43
 
44
  if __name__ == "__main__":
 
8
 
9
  defaults = {
10
  'model': 'models/text-bison-001',
11
+ 'temperature': 0.4,
12
  'candidate_count': 1,
13
  'top_k': 40,
14
  'top_p': 0.95,
 
24
 
25
  }
26
 
27
+ with gr.Blocks() as app:
28
+ def chat(text):
29
+ try:
30
+ response = palm.generate_text(
31
+ **defaults,
32
+ 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. If the sentence given is correct then the response will be the same as the input. Do not add any sentences other than the correction of the sentences.
33
+ Sentences: '{text}'"""
34
+ )
35
+ return response.result
36
+
37
+ except:
38
+ return "Sentences must be in English"
39
+
40
+ with gr.Column():
41
+ text = gr.Textbox(lines=6, label="Text", max_lines=5, placeholder="Write something awesome. It will be corrected automatically.")
42
+
43
+ with gr.Column():
44
+ output = gr.Textbox(lines=6, label="Output", max_lines=6, show_copy_button=True)
45
+ with gr.Row():
46
+ clr_btn = gr.ClearButton([text, output], variant="primary")
47
+ btn = gr.Button("Submit")
48
+ btn.click(fn=chat, inputs=text, outputs=output)
49
 
50
 
51
  if __name__ == "__main__":