BICORP commited on
Commit
bf9bdf5
·
verified ·
1 Parent(s): fa2e07e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -30
app.py CHANGED
@@ -3,54 +3,59 @@ from transformers import pipeline
3
 
4
  # Function to generate text based on the model
5
  def chatbot(user_input, history):
6
- # Load the selected model (using a hard-coded model for now)
7
- model = pipeline("text-generation", model="google/mt5-base")
8
-
9
- # Get the model's response
10
- response = model(user_input, max_length=50, temperature=1.0)[0]["generated_text"]
11
-
12
- # Append the user input and model's response to the history
13
  history.append({"role": "user", "content": user_input})
14
  history.append({"role": "assistant", "content": response})
15
-
16
- return history # Return the updated conversation history
17
 
18
- # Main interface layout with small input and large output
19
  def create_chat_interface():
20
  with gr.Blocks() as demo:
21
  gr.Markdown("# Chatbot Interface")
22
-
23
- # Define the chat interface
24
  chatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)
25
-
 
26
  with gr.Row(elem_id="input_container"):
27
- # Input field
28
- user_input = gr.Textbox(
29
- placeholder="Type your message here...", label=None, lines=1, elem_id="user_input"
30
- )
31
- # Send button
32
- send_button = gr.Button("📤", elem_id="send_button")
33
 
34
- # Add CSS for styling the input container and placing the button inside
35
  demo.css = """
36
  #input_container {
37
  display: flex;
38
- align-items: center;
39
- gap: 5px;
 
 
 
 
 
40
  }
41
  #user_input {
42
- flex-grow: 1;
43
- border: 1px solid #ccc;
44
  border-radius: 8px;
45
- padding: 10px;
 
 
46
  }
47
  #send_button {
48
- width: 40px;
49
- height: 40px;
 
 
 
 
50
  background-color: #007bff;
51
  color: white;
52
  border: none;
53
- border-radius: 50%;
54
  cursor: pointer;
55
  display: flex;
56
  justify-content: center;
@@ -60,8 +65,8 @@ def create_chat_interface():
60
  background-color: #0056b3;
61
  }
62
  """
63
-
64
- # Connect the input to the chatbot function via the Send button
65
  send_button.click(
66
  chatbot,
67
  inputs=[user_input, chatbot_component],
 
3
 
4
  # Function to generate text based on the model
5
  def chatbot(user_input, history):
6
+ # Mock model response for demo purposes
7
+ response = f"Echo: {user_input}"
 
 
 
 
 
8
  history.append({"role": "user", "content": user_input})
9
  history.append({"role": "assistant", "content": response})
10
+ return history
 
11
 
12
+ # Main interface layout
13
  def create_chat_interface():
14
  with gr.Blocks() as demo:
15
  gr.Markdown("# Chatbot Interface")
16
+
17
+ # Chat display
18
  chatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)
19
+
20
+ # Input and button container
21
  with gr.Row(elem_id="input_container"):
22
+ # Input field with the button inside
23
+ with gr.Box(elem_id="input_with_button"):
24
+ send_button = gr.Button("📤", elem_id="send_button")
25
+ user_input = gr.Textbox(
26
+ placeholder="Type your message here...", label=None, lines=1, elem_id="user_input"
27
+ )
28
 
29
+ # Custom CSS to position the send button inside the input box
30
  demo.css = """
31
  #input_container {
32
  display: flex;
33
+ justify-content: center;
34
+ margin-top: 10px;
35
+ }
36
+ #input_with_button {
37
+ position: relative;
38
+ width: 100%;
39
+ max-width: 600px;
40
  }
41
  #user_input {
42
+ width: 100%;
43
+ padding-left: 40px; /* To make space for the button */
44
  border-radius: 8px;
45
+ border: 1px solid #ccc;
46
+ height: 40px;
47
+ box-sizing: border-box;
48
  }
49
  #send_button {
50
+ position: absolute;
51
+ left: 5px;
52
+ top: 5px;
53
+ width: 30px;
54
+ height: 30px;
55
+ border-radius: 50%;
56
  background-color: #007bff;
57
  color: white;
58
  border: none;
 
59
  cursor: pointer;
60
  display: flex;
61
  justify-content: center;
 
65
  background-color: #0056b3;
66
  }
67
  """
68
+
69
+ # Link button click to the chatbot function
70
  send_button.click(
71
  chatbot,
72
  inputs=[user_input, chatbot_component],