charanhu commited on
Commit
f5b98ac
·
1 Parent(s): c76cba0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -31,29 +31,28 @@ def add_text(history, text):
31
  history = history + [(text, None)]
32
  return history, gr.Textbox(value="", interactive=False)
33
 
34
- def add_file(history, file):
35
- history = history + [((file.name,), None)]
36
- return history
37
-
38
- def bot(history, max_len, min_len, temp):
39
  prompt = history[-1][0]
40
- response = generate_text(prompt, max_length=max_len, min_length=min_len, temperature=temp)
41
- history[-1] = (prompt, response)
42
- yield history
 
 
 
43
 
44
  with gr.Blocks() as demo:
45
  chatbot = gr.Chatbot(
46
  [],
47
  elem_id="chatbot",
48
  bubble_full_width=False,
49
- avatar_images=(None, None), # You can add an avatar image if needed
50
  )
51
 
52
  with gr.Row():
53
- prompt_txt = gr.Textbox(
54
  scale=4,
55
  show_label=False,
56
- placeholder="Enter text and press enter",
57
  container=False,
58
  )
59
 
@@ -61,10 +60,10 @@ with gr.Blocks() as demo:
61
  min_len_slider = gr.Slider(0, 2048, 20, label="Min Length")
62
  temp_slider = gr.Slider(0.1, 2.0, 1.0, label="Temperature")
63
 
64
- txt_msg = prompt_txt.submit(add_text, [chatbot, prompt_txt], [chatbot, prompt_txt], queue=False).then(
65
- bot, chatbot, max_len_slider, min_len_slider, temp_slider, api_name="bot_response"
66
  )
67
- txt_msg.then(lambda: gr.Textbox(interactive=True), None, [prompt_txt], queue=False)
68
 
69
  chatbot.like(print_like_dislike, None, None)
70
 
 
31
  history = history + [(text, None)]
32
  return history, gr.Textbox(value="", interactive=False)
33
 
34
+ def bot(history, max_length=100, min_length=20, temperature=1.0):
 
 
 
 
35
  prompt = history[-1][0]
36
+ response = generate_text(prompt, max_length=max_length, min_length=min_length, temperature=temperature)
37
+ history[-1][1] = ""
38
+ for character in response:
39
+ history[-1][1] += character
40
+ time.sleep(0.05)
41
+ yield history
42
 
43
  with gr.Blocks() as demo:
44
  chatbot = gr.Chatbot(
45
  [],
46
  elem_id="chatbot",
47
  bubble_full_width=False,
48
+ avatar_images=(None, None), # Set avatar image path or URL
49
  )
50
 
51
  with gr.Row():
52
+ txt = gr.Textbox(
53
  scale=4,
54
  show_label=False,
55
+ placeholder="Enter text and press enter, or upload an image",
56
  container=False,
57
  )
58
 
 
60
  min_len_slider = gr.Slider(0, 2048, 20, label="Min Length")
61
  temp_slider = gr.Slider(0.1, 2.0, 1.0, label="Temperature")
62
 
63
+ txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
64
+ bot, chatbot, chatbot, max_len_slider, min_len_slider, temp_slider
65
  )
66
+ txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
67
 
68
  chatbot.like(print_like_dislike, None, None)
69