File size: 1,097 Bytes
da5ea0c
 
9a47eac
da5ea0c
 
9a47eac
 
2ef9c43
9a47eac
2ef9c43
da5ea0c
 
14f5355
da5ea0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14f5355
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()