bezaime commited on
Commit
4a18196
·
verified ·
1 Parent(s): 20d2574

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -69,13 +69,24 @@ rag_chain = (
69
 
70
  import gradio as gr
71
 
72
- # Function to process streaming responses
73
  def rag_memory_stream(message, history):
74
  partial_text = ""
75
  for new_text in rag_chain.stream(message):
76
  partial_text += new_text
77
  yield partial_text
78
 
 
 
 
 
 
 
 
 
 
 
 
79
  # Examples and app information
80
  examples = ['I need a car', 'What is the make and fuel type of a car?']
81
  description = "An advanced chatbot that helps you choose the right car based on your preferences and budget."
@@ -87,12 +98,13 @@ custom_theme = gr.themes.Base(primary_hue="blue", secondary_hue="green").set(
87
  body_text_color="#FFFFFF", # White text for contrast
88
  )
89
 
90
- # Additional UI Components
91
  with gr.Blocks(theme=custom_theme) as demo:
92
  gr.Markdown(f"# {title}")
93
  gr.Markdown(description)
94
 
95
  with gr.Tabs():
 
96
  with gr.Tab("Chat"):
97
  chat_interface = gr.ChatInterface(
98
  fn=rag_memory_stream,
@@ -101,8 +113,10 @@ with gr.Blocks(theme=custom_theme) as demo:
101
  fill_height=True,
102
  )
103
 
 
104
  with gr.Tab("Car Preferences"):
105
  gr.Markdown("### Provide your preferences to get tailored advice:")
 
106
  make = gr.Dropdown(
107
  choices=["Toyota", "Honda", "BMW", "Tesla", "Ford"],
108
  label="Preferred Make",
@@ -119,11 +133,24 @@ with gr.Blocks(theme=custom_theme) as demo:
119
  info="Choose the type of fuel you prefer.",
120
  )
121
  submit_button = gr.Button("Submit Preferences")
 
 
 
 
 
 
 
 
 
 
 
122
 
 
123
  with gr.Tab("Upload Documents"):
124
  gr.Markdown("### Upload any related documents for personalized suggestions:")
125
  file_upload = gr.File(label="Upload Car Listings or Preferences")
126
 
 
127
  with gr.Tab("Help"):
128
  gr.Markdown("### Need Assistance?")
129
  gr.Markdown(
@@ -146,4 +173,3 @@ with gr.Blocks(theme=custom_theme) as demo:
146
  # Launch the app
147
  if __name__ == "__main__":
148
  demo.launch()
149
-
 
69
 
70
  import gradio as gr
71
 
72
+ # Function for the chatbot response stream
73
  def rag_memory_stream(message, history):
74
  partial_text = ""
75
  for new_text in rag_chain.stream(message):
76
  partial_text += new_text
77
  yield partial_text
78
 
79
+ # Function to process car preferences
80
+ def process_preferences(make, budget, fuel_type):
81
+ return (
82
+ f"You've selected:\n"
83
+ f"- **Preferred Make**: {make}\n"
84
+ f"- **Budget**: ${budget}\n"
85
+ f"- **Fuel Type**: {fuel_type}\n\n"
86
+ f"Based on your preferences, I recommend exploring the latest models of {make} "
87
+ f"that fit your budget and offer {fuel_type.lower()} options!"
88
+ )
89
+
90
  # Examples and app information
91
  examples = ['I need a car', 'What is the make and fuel type of a car?']
92
  description = "An advanced chatbot that helps you choose the right car based on your preferences and budget."
 
98
  body_text_color="#FFFFFF", # White text for contrast
99
  )
100
 
101
+ # Advanced Interface with Car Preferences
102
  with gr.Blocks(theme=custom_theme) as demo:
103
  gr.Markdown(f"# {title}")
104
  gr.Markdown(description)
105
 
106
  with gr.Tabs():
107
+ # Chat Tab
108
  with gr.Tab("Chat"):
109
  chat_interface = gr.ChatInterface(
110
  fn=rag_memory_stream,
 
113
  fill_height=True,
114
  )
115
 
116
+ # Car Preferences Tab
117
  with gr.Tab("Car Preferences"):
118
  gr.Markdown("### Provide your preferences to get tailored advice:")
119
+
120
  make = gr.Dropdown(
121
  choices=["Toyota", "Honda", "BMW", "Tesla", "Ford"],
122
  label="Preferred Make",
 
133
  info="Choose the type of fuel you prefer.",
134
  )
135
  submit_button = gr.Button("Submit Preferences")
136
+ output = gr.Textbox(
137
+ label="Recommendation",
138
+ placeholder="Your recommendations will appear here...",
139
+ )
140
+
141
+ # Link the submit button to the processing function
142
+ submit_button.click(
143
+ process_preferences, # Function to call
144
+ inputs=[make, budget, fuel_type], # Inputs from UI
145
+ outputs=output, # Where to display the result
146
+ )
147
 
148
+ # Upload Documents Tab
149
  with gr.Tab("Upload Documents"):
150
  gr.Markdown("### Upload any related documents for personalized suggestions:")
151
  file_upload = gr.File(label="Upload Car Listings or Preferences")
152
 
153
+ # Help Tab
154
  with gr.Tab("Help"):
155
  gr.Markdown("### Need Assistance?")
156
  gr.Markdown(
 
173
  # Launch the app
174
  if __name__ == "__main__":
175
  demo.launch()