File size: 1,723 Bytes
ab39e24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import replicate
import os

key = ""
prompt = ""
personality = ""
def keys(newkey):
  global key
  key = str(newkey)
  print(key)
  return key

def AIPerson(personal):
  global personality
  personality = personal
  return personality
  
def user(user_message, history):
  global prompt
  prompt = user_message
  return "", history + [[user_message, None]]

def bot(history):
  global personality
  global prompt
  global key
  os.environ["REPLICATE_API_TOKEN"] = key
  print(prompt)
  print(personality)
  output = replicate.run(
      "nateraw/goliath-120b:39c0be5d2e96df975da94e8923535733d81179abed5f37c999afc5f7c33bf04e",
      input={
          "top_k": 50,
          "top_p": 1,
          "prompt": prompt,
          "temperature": 0.8,
          "max_new_tokens": 128,
          "prompt_template": f"{personality}\n\nUSER: {prompt}\nASSISTANT:",
          "presence_penalty": 1,
          "frequency_penalty": 0
      },
  )
  history[-1][1] = ''.join([w for w in output]).strip()
  return history

with gr.Blocks(css="style.css") as run:
  apikey = gr.Textbox(label="Enter Replicate API key", elem_classes="apikey")
  chatbot = gr.Chatbot(elem_classes="chatbox")
  msg = gr.Textbox(elem_classes="txtmsg")
  with gr.Row():
    submit = gr.Button("Submit", elem_classes="submit")
    clear = gr.Button("Clear", elem_classes="clear")
  pertxt = gr.Textbox(label="Enter AI Personality", elem_classes="aiperson")

  apikey.input(keys, apikey)
  os.environ["REPLICATE_API_TOKEN"] = key
  pertxt.input(AIPerson, pertxt)
  submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
      bot, chatbot, chatbot
  )
  clear.click(lambda: None, None, chatbot, queue=False)
run.launch(share=True)