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