Download app.py from anithai/java_chat: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/anithai/java_chat/resolve/9d3424b2b021981bbd61711d29d28ffe945eb74e/app.py
- Command line
-
hf download hf://spaces/anithai/java_chat@9d3424b2b021981bbd61711d29d28ffe945eb74e/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anithai/java_chat/resolve/9d3424b2b021981bbd61711d29d28ffe945eb74e/app.py
1.14 kB
| import gradio as gr | |
| import subprocess | |
| import shutil # To locate the Java path dynamically | |
| def chatbot_interface(question): | |
| java_path = shutil.which("java") # Finds the correct Java path | |
| if not java_path: | |
| return "Error: Java is not installed or not found in PATH." | |
| try: | |
| result = subprocess.run( | |
| [java_path, '-cp', '/app:/app/lib/json-20210307.jar', 'Main', question], | |
| capture_output=True, | |
| text=True | |
| ) | |
| response = result.stdout.strip() | |
| error_output = result.stderr.strip() | |
| if error_output: | |
| return f"Java Error: {error_output}" | |
| if not response: | |
| return "Error: No response received from the Java logic." | |
| return response | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=chatbot_interface, | |
| inputs=gr.Textbox(label="Enter your question"), | |
| outputs=gr.Textbox(label="Response"), | |
| title="Syllabus Related Answer Chatbot", | |
| description="Ask syllabus-related questions and get accurate responses." | |
| ) | |
| iface.launch(server_name="0.0.0.0", server_port=7860) | |