Spaces:
Build error
Build error
Download app.py from anithai/Java_Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/anithai/Java_Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/anithai/Java_Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anithai/Java_Chatbot/resolve/main/app.py
1.1 kB
| import gradio as gr | |
| import subprocess | |
| import shutil # For locating Java dynamically | |
| def chatbot_interface(question): | |
| # Locate Java path dynamically | |
| java_path = shutil.which("java") | |
| if not java_path: | |
| return "Error: Java is still not installed or cannot be found." | |
| try: | |
| result = subprocess.run( | |
| [java_path, '-cp', '.:/app/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() | |