Satyam-Singh commited on
Commit
b3d2faf
·
verified ·
1 Parent(s): bfe7e33

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import os
4
+ import google.generativeai as palm
5
+
6
+ palm.configure(
7
+ api_key=os.getenv("api_key")
8
+ )
9
+
10
+ model_bison = "models/chat-bison-001"
11
+
12
+ def generate_text(prompt, examples, model=model_bison, temperature=0.25):
13
+ return palm.chat(model=model, temperature=temperature, examples=examples, messages=prompt).last
14
+
15
+ def generate(prompt, history, temperature=0.25):
16
+ examples = [(item[0], item[1]) for item in history]
17
+ output = generate_text(prompt, examples, model_bison, temperature)
18
+ return output
19
+
20
+ additional_inputs=[
21
+ gr.Slider(
22
+ label="Temperature",
23
+ value=0.25,
24
+ minimum=0.0,
25
+ maximum=1.0,
26
+ step=0.05,
27
+ interactive=True,
28
+ info="Higher values produce more diverse outputs",
29
+ )
30
+ ]
31
+
32
+ css = """
33
+ #mkd {
34
+ height: 500px;
35
+ overflow: auto;
36
+ border: 1px solid #ccc;
37
+ }
38
+ """
39
+
40
+ with gr.Blocks(css=css) as demo:
41
+ gr.HTML("<h1><center>PaLM 2 Chat by <a href='https://rishiraj.github.io/'>Rishiraj Acharya</a></center></h1>")
42
+ gr.ChatInterface(
43
+ generate,
44
+ additional_inputs=additional_inputs,
45
+ examples=[["What is the secret to life?"], ["Write me a recipe for pancakes."]]
46
+ )
47
+
48
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ huggingface_hub
2
+ google.generativeai