Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import google.generativeai as palm
|
3 |
+
import os
|
4 |
+
|
5 |
+
api_key = os.environ("api_key")
|
6 |
+
|
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,
|
15 |
+
'max_output_tokens': 1024,
|
16 |
+
'stop_sequences': [],
|
17 |
+
'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}]
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
def chat(Sentences):
|
22 |
+
response = palm.generate_text(
|
23 |
+
**defaults,
|
24 |
+
prompt=f"""Correct this sentences and correct the grammar. Do not add the quotation marks on your correction sentences: '{Sentences}'"""
|
25 |
+
)
|
26 |
+
return response.result
|
27 |
+
|
28 |
+
demo = gr.Interface(fn=chat, inputs=gr.Textbox(lines=10), outputs=gr.Textbox(lines=10), allow_flagging="never")
|
29 |
+
|
30 |
+
demo.launch(debug=True)
|