java_chat / app.py
anithai's picture
app.py
5ca9a87 verified
Raw History Blame
980 Bytes
import gradio as gr
import subprocess
def chatbot_interface(question):
try:
# Use full path to Java if necessary
result = subprocess.run(
['/usr/bin/java', '-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)