saherPervaiz commited on
Commit
b970dfa
·
verified ·
1 Parent(s): b29c175

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -9
app.py CHANGED
@@ -1,14 +1,29 @@
1
  import gradio as gr
2
  from utils import generate_response
3
 
 
 
 
 
 
 
4
  # Define chatbot interaction function
5
- def chat(user_input, chat_history):
6
  try:
7
- # Generate response
8
  response = generate_response(user_input)
 
 
 
 
 
 
 
 
9
  # Update chat history
10
  chat_history.append(("User", user_input))
11
  chat_history.append(("AI", response))
 
12
  # Format chat history for display with a conversational style
13
  formatted_history = "\n".join(
14
  [f"{role}: {message}" for role, message in chat_history]
@@ -17,7 +32,7 @@ def chat(user_input, chat_history):
17
  except Exception as e:
18
  return f"Error: {e}", chat_history
19
 
20
- # Create Gradio interface with updated modern design
21
  with gr.Blocks(css="""
22
  body {
23
  background-color: #f7f7f7;
@@ -36,11 +51,12 @@ with gr.Blocks(css="""
36
  padding: 30px;
37
  border-radius: 15px;
38
  box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.1);
 
39
  }
40
  .gradio-container .textbox, .gradio-container .button {
41
  background-color: #eeeeee;
42
  color: #333;
43
- border: 1px solid #ccc;
44
  border-radius: 10px;
45
  padding: 12px;
46
  font-size: 16px;
@@ -60,10 +76,10 @@ with gr.Blocks(css="""
60
  #chatbox {
61
  height: 350px;
62
  overflow-y: auto;
63
- border: none;
64
  padding: 20px;
65
  border-radius: 10px;
66
- background-color: #f1f1f1;
67
  color: #333;
68
  margin-bottom: 20px;
69
  font-size: 14px;
@@ -86,8 +102,8 @@ with gr.Blocks(css="""
86
  margin-left: auto;
87
  }
88
  """) as demo:
89
- gr.Markdown("## 🤖 **Professional Groq Chatbot**")
90
- gr.Markdown("Type your message below to chat with the AI!")
91
 
92
  # Define layout with vertical alignment
93
  with gr.Column():
@@ -108,13 +124,21 @@ with gr.Blocks(css="""
108
  elem_id="chatbox",
109
  )
110
 
 
 
 
 
 
 
 
 
111
  # State to hold chat history
112
  chat_history = gr.State([])
113
 
114
  # Button functionalities
115
  submit_button.click(
116
  fn=chat,
117
- inputs=[user_input, chat_history],
118
  outputs=[chatbot_output, chat_history],
119
  )
120
 
 
1
  import gradio as gr
2
  from utils import generate_response
3
 
4
+ # Placeholder function for image description (replace this with a real model or API)
5
+ def describe_image(image):
6
+ # This is a placeholder. In a real implementation, use a model like CLIP or other image captioning models.
7
+ # You can integrate an API or a pre-trained model to generate descriptions for images.
8
+ return "This is a placeholder description for the uploaded image."
9
+
10
  # Define chatbot interaction function
11
+ def chat(user_input, chat_history, image):
12
  try:
13
+ # Generate text response
14
  response = generate_response(user_input)
15
+
16
+ # If an image is uploaded, describe it
17
+ if image is not None:
18
+ image_description = describe_image(image)
19
+ response += f"\n\n[Image Description]: {image_description}"
20
+ else:
21
+ image_description = "No image uploaded."
22
+
23
  # Update chat history
24
  chat_history.append(("User", user_input))
25
  chat_history.append(("AI", response))
26
+
27
  # Format chat history for display with a conversational style
28
  formatted_history = "\n".join(
29
  [f"{role}: {message}" for role, message in chat_history]
 
32
  except Exception as e:
33
  return f"Error: {e}", chat_history
34
 
35
+ # Create Gradio interface with updated light boundary design and image upload
36
  with gr.Blocks(css="""
37
  body {
38
  background-color: #f7f7f7;
 
51
  padding: 30px;
52
  border-radius: 15px;
53
  box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.1);
54
+ border: 1px solid #dcdcdc; /* Light border */
55
  }
56
  .gradio-container .textbox, .gradio-container .button {
57
  background-color: #eeeeee;
58
  color: #333;
59
+ border: 1px solid #dcdcdc; /* Light border */
60
  border-radius: 10px;
61
  padding: 12px;
62
  font-size: 16px;
 
76
  #chatbox {
77
  height: 350px;
78
  overflow-y: auto;
79
+ border: 1px solid #dcdcdc; /* Light border */
80
  padding: 20px;
81
  border-radius: 10px;
82
+ background-color: #f9f9f9;
83
  color: #333;
84
  margin-bottom: 20px;
85
  font-size: 14px;
 
102
  margin-left: auto;
103
  }
104
  """) as demo:
105
+ gr.Markdown("## 🤖 **Professional Groq Chatbot with Image Description**")
106
+ gr.Markdown("Type your message below or upload an image to get a description!")
107
 
108
  # Define layout with vertical alignment
109
  with gr.Column():
 
124
  elem_id="chatbox",
125
  )
126
 
127
+ # Image upload component
128
+ image_input = gr.Image(
129
+ label="Upload Image for Description",
130
+ type="pil", # PIL (Python Imaging Library) type for image input
131
+ interactive=True,
132
+ elem_id="image-upload",
133
+ )
134
+
135
  # State to hold chat history
136
  chat_history = gr.State([])
137
 
138
  # Button functionalities
139
  submit_button.click(
140
  fn=chat,
141
+ inputs=[user_input, chat_history, image_input],
142
  outputs=[chatbot_output, chat_history],
143
  )
144