Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
|
| 238 |
-
|
| 239 |
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 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:
|