cstr commited on
Commit
8d039b9
·
verified ·
1 Parent(s): 895ad65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -25
app.py CHANGED
@@ -212,35 +212,54 @@ def send_to_model(*args, **kwargs): # Correct the outputs here
212
  return f"Error: {str(e)}", None # Return error message and None for the file
213
 
214
  def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model, hf_api_key,
215
- groq_model_choice, groq_api_key, openai_api_key, openai_model_choice): # Added openai_model_choice
216
- try:
217
- if model_selection == "Clipboard only":
218
- return "Use copy/paste for processing", None
219
-
220
- if model_selection == "HuggingFace Inference":
221
- # ... (Existing logic)
222
-
223
- elif model_selection == "Groq API":
224
- # ... (Existing logic)
225
-
226
- elif model_selection == "OpenAI ChatGPT":
227
- if not openai_api_key:
228
- return "Error: OpenAI API key required", None
229
- summary = send_to_openai(prompt, openai_api_key, model=openai_model_choice) # Use openai_model_choice
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
- else:
232
- return "Error: Invalid model selection", None
233
 
234
- with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
235
- f.write(summary)
236
- download_file = f.name
237
 
238
- return summary, download_file
239
 
240
- except Exception as e:
241
- error_msg = f"Error processing request: {str(e)}"
242
- logging.error(error_msg)
243
- return error_msg, None # Return the error message
244
 
245
  def send_to_hf_inference(prompt: str, model_name: str, api_key: str) -> str:
246
  try:
 
212
  return f"Error: {str(e)}", None # Return error message and None for the file
213
 
214
  def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model, hf_api_key,
215
+ groq_model_choice, groq_api_key, openai_api_key, openai_model_choice):
216
+ try:
217
+ if model_selection == "Clipboard only":
218
+ return "Use copy/paste for processing", None
219
+
220
+ elif model_selection == "HuggingFace Inference":
221
+ if not hf_api_key:
222
+ return "Error: HuggingFace API key required", None
223
+ if not hf_model_choice:
224
+ return "Error: Select a HuggingFace model", None
225
+ model_id = hf_custom_model if hf_model_choice == "Custom Model" else model_registry.hf_models[hf_model_choice]
226
+ try:
227
+ summary = send_to_hf_inference(prompt, model_id, hf_api_key)
228
+ except Exception as e:
229
+ return f"Error with HuggingFace Inference: {e}", None
230
+
231
+
232
+ elif model_selection == "Groq API":
233
+ if not groq_api_key:
234
+ return "Error: Groq API key required", None
235
+ if not groq_model_choice:
236
+ return "Error: Select a Groq model", None
237
+ try:
238
+ summary = send_to_groq(prompt, groq_model_choice, groq_api_key)
239
+ except Exception as e:
240
+ return f"Error with Groq API: {e}", None
241
+
242
+ elif model_selection == "OpenAI ChatGPT":
243
+ if not openai_api_key:
244
+ return "Error: OpenAI API key required", None
245
+ try:
246
+ summary = send_to_openai(prompt, openai_api_key, model=openai_model_choice)
247
+ except Exception as e:
248
+ return f"Error with OpenAI API: {e}", None
249
 
250
+ else:
251
+ return "Error: Invalid model selection", None
252
 
253
+ with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
254
+ f.write(summary)
255
+ download_file = f.name
256
 
257
+ return summary, download_file
258
 
259
+ except Exception as e: # Outer exception handler
260
+ error_msg = f"An unexpected error occurred: {str(e)}"
261
+ logging.error(error_msg)
262
+ return error_msg, None
263
 
264
  def send_to_hf_inference(prompt: str, model_name: str, api_key: str) -> str:
265
  try: