Download app.py from OjciecTadeusz/tools-function-calling: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/spaces/OjciecTadeusz/tools-function-calling/resolve/main/app.py
- Command line
-
hf download hf://spaces/OjciecTadeusz/tools-function-calling/app.py
-
curl -L -o app.py https://huggingface.co/spaces/OjciecTadeusz/tools-function-calling/resolve/main/app.py
988 Bytes
| # app.py | |
| from gradio_client import Client | |
| import gradio as gr | |
| from tools import add_numbers | |
| def chatbot_function_calling(user_message, history): | |
| if "add" in user_message.lower(): | |
| # Przykładowe parsowanie komendy | |
| try: | |
| parts = user_message.split() | |
| a = int(parts[1]) | |
| b = int(parts[2]) | |
| result = add_numbers(a, b) | |
| response = f"Result: {result}" | |
| except Exception as e: | |
| response = f"Error: {str(e)}" | |
| else: | |
| response = "I'm sorry, I don't understand the command." | |
| history.append((user_message, response)) | |
| return history, history | |
| iface = gr.ChatInterface( | |
| fn=chatbot_function_calling, | |
| chatbot=gr.Chatbot(height=400), | |
| textbox=gr.Textbox(show_label=False, placeholder="Send a message..."), | |
| title="Function Calling Chatbot", | |
| description="This chatbot can perform simple operations like addition." | |
| ) | |
| iface.launch(server_name="0.0.0.0", server_port=7860) |