ShivaPrakash commited on
Commit
7e1ca3e
1 Parent(s): 43f9567

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -15,18 +15,16 @@ def print_like_dislike(x: gr.LikeData):
15
  def add_message(history, message):
16
  # Since we're now using gr.Textbox, we only handle text inputs
17
  if message is not None:
18
- prompt = message
19
- response = requests.get(f"https://shivaprakash-fastapi.hf.space/generate/{prompt}")
20
- response = (response.json())['response']
21
- history.append((message, response))
22
  return history, gr.Textbox(value=None, interactive=False)
23
 
24
  def bot(history):
25
- response = history[-1][1]
26
  history[-1][1] = ""
27
  for character in response:
28
  history[-1][1] += character
29
- time.sleep(0.01)
30
  yield history
31
 
32
  with gr.Blocks() as demo:
@@ -37,13 +35,12 @@ with gr.Blocks() as demo:
37
  )
38
 
39
  # Use gr.Textbox for chat input
40
- chat_input = gr.Textbox(placeholder="Enter message ...", show_label=True)
41
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
42
- bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
43
  bot_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input])
44
-
45
  chatbot.like(print_like_dislike, None, None)
46
 
47
  demo.queue()
48
  demo.launch()
49
-
 
15
  def add_message(history, message):
16
  # Since we're now using gr.Textbox, we only handle text inputs
17
  if message is not None:
18
+ history.append((message, ''))
19
+ print(history)
 
 
20
  return history, gr.Textbox(value=None, interactive=False)
21
 
22
  def bot(history):
23
+ response = random.choice(["Noted. Will check that and get back", "Okay. Interesting!!","Hmm! Can you give me more info on this"])
24
  history[-1][1] = ""
25
  for character in response:
26
  history[-1][1] += character
27
+ time.sleep(0.1)
28
  yield history
29
 
30
  with gr.Blocks() as demo:
 
35
  )
36
 
37
  # Use gr.Textbox for chat input
38
+ chat_input = gr.Textbox(placeholder="Enter message ...", show_label=True, label = "Input prompt")
39
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
40
+ bot_msg = chat_msg.then(bot,chatbot,chatbot, api_name="bot_response")
41
  bot_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input])
42
+
43
  chatbot.like(print_like_dislike, None, None)
44
 
45
  demo.queue()
46
  demo.launch()