vdmbrsv commited on
Commit
f1c6649
·
verified ·
1 Parent(s): 37fde68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -7
app.py CHANGED
@@ -74,16 +74,19 @@ class AuginiDarkTheme(Base):
74
  )
75
 
76
  class AuginiChat:
77
- def __init__(self):
78
  self.df: Optional[pd.DataFrame] = None
 
 
79
  # Initialize Augini with the API key directly
80
  self.augini = Augini(
81
  api_key=os.environ.get('OPENROUTER_TOKEN'),
82
  use_openrouter=True,
83
- model='gpt-4o-mini',
84
- temperature=0.7,
85
- max_tokens=1500,
86
  )
 
87
 
88
  def upload_file(self, file) -> str:
89
  """Handle file upload and return preview"""
@@ -127,9 +130,20 @@ class AuginiChat:
127
  error_msg = f"❌ Error processing message: {str(e)}"
128
  return "", history + [(message, error_msg)]
129
 
 
 
 
 
 
 
 
 
 
 
 
130
  def create_app():
131
- # Initialize the chat handler
132
- chat_handler = AuginiChat()
133
 
134
  # JavaScript to force dark theme - added to head
135
  dark_mode_script = """
@@ -147,6 +161,14 @@ def create_app():
147
  setDarkTheme();
148
  </script>
149
  """
 
 
 
 
 
 
 
 
150
 
151
  # Create the Gradio interface with dark theme script in head
152
  with gr.Blocks(head=dark_mode_script) as app:
@@ -159,6 +181,34 @@ def create_app():
159
  > 💡 **Tip**: Ask questions about patterns, relationships, or any aspect of your data. **augini** will provide detailed, evidence-based answers.
160
  """, elem_classes=["center-content"])
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  with gr.Row(elem_classes=["container"]):
163
  # Left sidebar for file upload
164
  with gr.Column(scale=1, elem_classes=["sidebar"]):
@@ -269,4 +319,4 @@ def create_app():
269
 
270
  if __name__ == "__main__":
271
  app = create_app()
272
- app.launch(share=True)
 
74
  )
75
 
76
  class AuginiChat:
77
+ def __init__(self, model: str, temperature: float = 0.7):
78
  self.df: Optional[pd.DataFrame] = None
79
+ self.model = model
80
+ self.temperature = temperature
81
  # Initialize Augini with the API key directly
82
  self.augini = Augini(
83
  api_key=os.environ.get('OPENROUTER_TOKEN'),
84
  use_openrouter=True,
85
+ model=self.model,
86
+ temperature=self.temperature,
87
+ max_tokens=1500,
88
  )
89
+
90
 
91
  def upload_file(self, file) -> str:
92
  """Handle file upload and return preview"""
 
130
  error_msg = f"❌ Error processing message: {str(e)}"
131
  return "", history + [(message, error_msg)]
132
 
133
+ def update_model_settings(self, model_name: str, temperature: float) -> None:
134
+ """Update the model settings and reinitialize Augini."""
135
+ self.model = model_name
136
+ self.temperature = temperature
137
+ self.augini = Augini(
138
+ api_key=os.environ.get('OPENROUTER_TOKEN'),
139
+ use_openrouter=True,
140
+ model=self.model,
141
+ temperature=self.temperature,
142
+ )
143
+
144
  def create_app():
145
+ # Initialize the chat handler with default settings
146
+ chat_handler = AuginiChat(model='openai/gpt-4o-mini', temperature=0.7)
147
 
148
  # JavaScript to force dark theme - added to head
149
  dark_mode_script = """
 
161
  setDarkTheme();
162
  </script>
163
  """
164
+
165
+ available_models = [
166
+ "mistralai/mistral-nemo",
167
+ "meta-llama/llama-3.3-70b-instruct",
168
+ "qwen/qwen-2.5-72b-instruct",
169
+ "openai/gpt-4o-mini",
170
+ "meta-llama/llama-3.2-3b-instruct",
171
+ ]
172
 
173
  # Create the Gradio interface with dark theme script in head
174
  with gr.Blocks(head=dark_mode_script) as app:
 
181
  > 💡 **Tip**: Ask questions about patterns, relationships, or any aspect of your data. **augini** will provide detailed, evidence-based answers.
182
  """, elem_classes=["center-content"])
183
 
184
+ with gr.Accordion("⚙️ Model Settings", open=False):
185
+ model_dropdown = gr.Dropdown(
186
+ label="Select Model",
187
+ choices=available_models,
188
+ value="openai/gpt-4o-mini"
189
+ )
190
+ temperature_slider = gr.Slider(
191
+ label="Temperature",
192
+ minimum=0.0,
193
+ maximum=1.0,
194
+ value=0.7,
195
+ step=0.05
196
+ )
197
+
198
+ def update_settings(model_name, temperature):
199
+ chat_handler.update_model_settings(model_name, temperature)
200
+ return f"Model settings updated: {model_name}, Temperature: {temperature}"
201
+
202
+ update_button = gr.Button("Update Model Settings")
203
+ update_status = gr.Textbox(label="Update Status", interactive=False)
204
+
205
+ update_button.click(
206
+ update_settings,
207
+ inputs=[model_dropdown, temperature_slider],
208
+ outputs=[update_status]
209
+ )
210
+
211
+
212
  with gr.Row(elem_classes=["container"]):
213
  # Left sidebar for file upload
214
  with gr.Column(scale=1, elem_classes=["sidebar"]):
 
319
 
320
  if __name__ == "__main__":
321
  app = create_app()
322
+ app.launch(share=True)