Update app.py
Browse files
app.py
CHANGED
@@ -77,7 +77,7 @@ def load_methods_from_tools():
|
|
77 |
method_mapping = load_methods_from_tools()
|
78 |
|
79 |
# Main request router method
|
80 |
-
def
|
81 |
# Reload methods to include newly created tools
|
82 |
global method_mapping
|
83 |
method_mapping = load_methods_from_tools()
|
@@ -93,7 +93,26 @@ def request_router(name: str, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
93 |
return output
|
94 |
except Exception as e:
|
95 |
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Gradio Interface
|
98 |
def launch_gradio_app():
|
99 |
with gr.Blocks() as demo:
|
@@ -112,5 +131,22 @@ def launch_gradio_app():
|
|
112 |
|
113 |
demo.launch()
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
if __name__ == "__main__":
|
116 |
launch_gradio_app()
|
|
|
77 |
method_mapping = load_methods_from_tools()
|
78 |
|
79 |
# Main request router method
|
80 |
+
def request_routerOld(name: str, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
81 |
# Reload methods to include newly created tools
|
82 |
global method_mapping
|
83 |
method_mapping = load_methods_from_tools()
|
|
|
93 |
return output
|
94 |
except Exception as e:
|
95 |
return {"error": str(e)}
|
96 |
+
|
97 |
+
def request_router(name: str, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
98 |
+
global method_mapping
|
99 |
+
method_mapping = load_methods_from_tools()
|
100 |
|
101 |
+
logging.info(f"Request to invoke method: {name} with input: {input_data}")
|
102 |
+
method = method_mapping.get(name)
|
103 |
+
if method is None:
|
104 |
+
error_message = "Method not found"
|
105 |
+
logging.error(error_message)
|
106 |
+
return {"error": error_message}
|
107 |
+
|
108 |
+
try:
|
109 |
+
output = method(input_data)
|
110 |
+
logging.info(f"Output: {output}")
|
111 |
+
return output
|
112 |
+
except Exception as e:
|
113 |
+
logging.error(f"Error occurred: {str(e)}")
|
114 |
+
return {"error": str(e)}
|
115 |
+
|
116 |
# Gradio Interface
|
117 |
def launch_gradio_app():
|
118 |
with gr.Blocks() as demo:
|
|
|
131 |
|
132 |
demo.launch()
|
133 |
|
134 |
+
import logging
|
135 |
+
|
136 |
+
# Set up logging configuration
|
137 |
+
logging.basicConfig(level=logging.INFO, filename='request_logs.txt',
|
138 |
+
format='%(asctime)s - %(message)s')
|
139 |
+
|
140 |
+
def log_payload(*args, **kwargs):
|
141 |
+
# Log the incoming payload
|
142 |
+
logging.info(f"Received payload: args={args}, kwargs={kwargs}")
|
143 |
+
return main_function(*args, **kwargs)
|
144 |
+
|
145 |
+
def main_function(name):
|
146 |
+
return "Hello " + name + "!!"
|
147 |
+
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
if __name__ == "__main__":
|
152 |
launch_gradio_app()
|