taufiqdp commited on
Commit
41dbe2e
1 Parent(s): 2c36cb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -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.4,
12
  'candidate_count': 1,
13
  'top_k': 40,
14
  'top_p': 0.95,
@@ -24,27 +24,29 @@ defaults = {
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. Do not add any sentences other than the correction of the sentences. If does not appear to have a specific name or meaning in any known language or it appears to be a random string of letters without a clear linguistic structure or purpose give response 'Sentences must be in English'.
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])
47
- btn = gr.Button("Submit", variant="primary")
48
  btn.click(fn=chat, inputs=text, outputs=output)
49
 
50
 
 
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
 
25
  }
26
 
27
+ with open("example.txt") as f:
28
+ example = f.read()
29
+
30
  with gr.Blocks() as app:
31
  def chat(text):
32
+ response = palm.generate_text(
33
+ **defaults,
34
+ prompt = f"""Rewrite the following sentence to fix the grammar issues and correct the sentence.
35
+ {example}
36
+ input: {text}
37
+ fixed"""
38
+ )
39
+ return response.result
 
 
40
 
41
  with gr.Column():
42
+ text = gr.Textbox(lines=4, label="Text", max_lines=4, placeholder="Write something awesome. It will be corrected automatically.")
43
+
44
  with gr.Column():
45
+ output = gr.Textbox(lines=4, label="Output", max_lines=4, show_copy_button=True)
46
+
47
  with gr.Row():
48
+ clr_btn = gr.ClearButton([text, output], variant="primary")
49
+ btn = gr.Button("Submit")
50
  btn.click(fn=chat, inputs=text, outputs=output)
51
 
52