Update app.py
Browse files
app.py
CHANGED
|
@@ -50,26 +50,31 @@ def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name =
|
|
| 50 |
tuple: (answer, console_logs) - The answer to the question and captured console output
|
| 51 |
"""
|
| 52 |
if not question:
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
if not openai_api_key:
|
| 57 |
-
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
if not gemini_api_key:
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
if not anthropic_api_key:
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
is_valid, err_msg = validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name)
|
| 69 |
|
| 70 |
if not is_valid:
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
if file_name:
|
| 75 |
file_name = f"files/{file_name}"
|
|
@@ -94,9 +99,9 @@ def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name =
|
|
| 94 |
|
| 95 |
return answer, console_logs
|
| 96 |
except Exception as e:
|
| 97 |
-
|
| 98 |
-
gr.Warning(
|
| 99 |
-
return
|
| 100 |
|
| 101 |
# Helper functions
|
| 102 |
|
|
|
|
| 50 |
tuple: (answer, console_logs) - The answer to the question and captured console output
|
| 51 |
"""
|
| 52 |
if not question:
|
| 53 |
+
msg = "Question is required."
|
| 54 |
+
gr.Warning(msg)
|
| 55 |
+
return None, msg
|
| 56 |
|
| 57 |
if not openai_api_key:
|
| 58 |
+
msg = "OpenAI API Key is required."
|
| 59 |
+
gr.Warning(msg)
|
| 60 |
+
return None, msg
|
| 61 |
|
| 62 |
if not gemini_api_key:
|
| 63 |
+
msg = "Gemini API Key is required."
|
| 64 |
+
gr.Warning(msg)
|
| 65 |
+
return None, msg
|
| 66 |
|
| 67 |
if not anthropic_api_key:
|
| 68 |
+
msg = "Anthropic API Key is required."
|
| 69 |
+
gr.Warning(msg)
|
| 70 |
+
return None, msg
|
| 71 |
|
| 72 |
is_valid, err_msg = validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name)
|
| 73 |
|
| 74 |
if not is_valid:
|
| 75 |
+
msg = f"Invalid input: {err_msg}"
|
| 76 |
+
gr.Warning(msg)
|
| 77 |
+
return None, msg
|
| 78 |
|
| 79 |
if file_name:
|
| 80 |
file_name = f"files/{file_name}"
|
|
|
|
| 99 |
|
| 100 |
return answer, console_logs
|
| 101 |
except Exception as e:
|
| 102 |
+
msg = str(e)
|
| 103 |
+
gr.Warning(msg)
|
| 104 |
+
return None, f"Error: {msg}"
|
| 105 |
|
| 106 |
# Helper functions
|
| 107 |
|