bezaime commited on
Commit
7eb9f14
·
verified ·
1 Parent(s): ed4e4a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -18
app.py CHANGED
@@ -70,19 +70,23 @@ rag_chain = (
70
 
71
  import gradio as gr
72
 
73
- # Mock for rag_chain.stream or similar streaming function
74
- class MockRAGChain:
75
- @staticmethod
76
- def stream(message):
77
- response = f"Processing your message: {message}"
78
- yield response # Mock single response for testing
79
-
80
- rag_chain = MockRAGChain() # Replace with your actual RAG chain object
81
-
82
- # Function for chatbot responses (simplified for testing)
83
  def rag_memory_stream(message, history):
84
- for response in rag_chain.stream(message): # Streaming response
85
- return response # Mock response for now
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  # Examples and app information
88
  examples = ['I need a car', 'What is the make and fuel type of a car?']
@@ -95,7 +99,7 @@ custom_theme = gr.themes.Base(primary_hue="blue", secondary_hue="green").set(
95
  body_text_color="#000000", # Black text
96
  )
97
 
98
- # Interface with Car Preferences and Chat
99
  with gr.Blocks(theme=custom_theme) as demo:
100
  gr.Markdown(f"# {title}")
101
  gr.Markdown(description)
@@ -104,15 +108,69 @@ with gr.Blocks(theme=custom_theme) as demo:
104
  # Chat Tab
105
  with gr.Tab("Chat"):
106
  chat_interface = gr.ChatInterface(
107
- fn=rag_memory_stream, # Simplified chat function
108
- type="value", # Use "value" to simplify interactions
109
  examples=examples,
 
110
  )
111
 
112
- # Additional Tabs (optional)
113
  with gr.Tab("Car Preferences"):
114
- gr.Markdown("This tab handles car preferences (not modified here).")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  # Launch the app
117
  if __name__ == "__main__":
118
- demo.launch()
 
70
 
71
  import gradio as gr
72
 
73
+ # Function for the chatbot response stream
 
 
 
 
 
 
 
 
 
74
  def rag_memory_stream(message, history):
75
+ partial_text = ""
76
+ for new_text in rag_chain.stream(message):
77
+ partial_text += new_text
78
+ yield partial_text
79
+
80
+ # Function to process car preferences
81
+ def process_preferences(make, budget, fuel_type):
82
+ return (
83
+ f"You've selected:\n"
84
+ f"- **Preferred Make**: {make}\n"
85
+ f"- **Budget**: ${budget}\n"
86
+ f"- **Fuel Type**: {fuel_type}\n\n"
87
+ f"Based on your preferences, I recommend exploring the latest models of {make} "
88
+ f"that fit your budget and offer {fuel_type.lower()} options!"
89
+ )
90
 
91
  # Examples and app information
92
  examples = ['I need a car', 'What is the make and fuel type of a car?']
 
99
  body_text_color="#000000", # Black text
100
  )
101
 
102
+ # Advanced Interface with Car Preferences
103
  with gr.Blocks(theme=custom_theme) as demo:
104
  gr.Markdown(f"# {title}")
105
  gr.Markdown(description)
 
108
  # Chat Tab
109
  with gr.Tab("Chat"):
110
  chat_interface = gr.ChatInterface(
111
+ fn=rag_memory_stream,
112
+ type="messages",
113
  examples=examples,
114
+ fill_height=True,
115
  )
116
 
117
+ # Car Preferences Tab
118
  with gr.Tab("Car Preferences"):
119
+ gr.Markdown("### Provide your preferences to get tailored advice:")
120
+
121
+ make = gr.Dropdown(
122
+ choices=["Toyota", "Honda", "BMW", "Tesla", "Ford"],
123
+ label="Preferred Make",
124
+ info="Choose the car manufacturer you prefer.",
125
+ )
126
+ budget = gr.Slider(
127
+ minimum=5000, maximum=100000, step=500,
128
+ label="Budget (in USD)",
129
+ info="Select your budget range.",
130
+ )
131
+ fuel_type = gr.Radio(
132
+ choices=["Gasoline", "Diesel", "Electric", "Hybrid"],
133
+ label="Fuel Type",
134
+ info="Choose the type of fuel you prefer.",
135
+ )
136
+ submit_button = gr.Button("Submit Preferences")
137
+ output = gr.Textbox(
138
+ label="Recommendation",
139
+ placeholder="Your recommendations will appear here...",
140
+ )
141
+
142
+ # Link the submit button to the processing function
143
+ submit_button.click(
144
+ process_preferences, # Function to call
145
+ inputs=[make, budget, fuel_type], # Inputs from UI
146
+ outputs=output, # Where to display the result
147
+ )
148
+
149
+ # Upload Documents Tab
150
+ with gr.Tab("Upload Documents"):
151
+ gr.Markdown("### Upload any related documents for personalized suggestions:")
152
+ file_upload = gr.File(label="Upload Car Listings or Preferences")
153
+
154
+ # Help Tab
155
+ with gr.Tab("Help"):
156
+ gr.Markdown("### Need Assistance?")
157
+ gr.Markdown(
158
+ """
159
+ - Use the **Chat** tab to ask questions about cars.
160
+ - Fill in your **Car Preferences** for tailored recommendations.
161
+ - Upload files in the **Upload Documents** tab.
162
+ - Contact support at: [email protected]
163
+ """
164
+ )
165
+
166
+ gr.Markdown("### About")
167
+ gr.Markdown(
168
+ """
169
+ This chatbot is powered by LangChain and Groq API for real-time AI interactions.
170
+ Designed to provide personalized car-buying assistance!
171
+ """
172
+ )
173
 
174
  # Launch the app
175
  if __name__ == "__main__":
176
+ demo.launch()