File size: 3,048 Bytes
1f883cc
 
c3d12c3
1f883cc
 
 
 
 
c3d12c3
 
1f883cc
 
 
 
 
 
 
c3d12c3
 
1f883cc
 
 
 
 
 
 
c3d12c3
 
1f883cc
 
 
 
 
 
 
c3d12c3
 
1f883cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr
import requests
import json  # Import json module to parse response text

# Function to call the "Previous Cases" API (cts endpoint)
def previous_cases(query):
    try:
        response = requests.post("https://aaronanoronha-haha.hf.space/cts", json={"topic": query})
        data = json.loads(response.text)  # Parse JSON string into dictionary
        return data.get("response", "No response found")  # Extract 'response' field
    except Exception as e:
        return f"Error: {e}"

# Function to call the "Law Navigation" API (lsi endpoint)
def law_navigation(query):
    try:
        response = requests.post("https://aaronanoronha-haha.hf.space/lsi", json={"topic": query})
        data = json.loads(response.text)
        return data.get("response", "No response found")
    except Exception as e:
        return f"Error: {e}"

# Function to call the "Judgment Prediction" API (pcr endpoint)
def judgment_prediction(query):
    try:
        response = requests.post("https://aaronanoronha-haha.hf.space/pcr", json={"topic": query})
        data = json.loads(response.text)
        return data.get("response", "No response found")
    except Exception as e:
        return f"Error: {e}"

# Function to call the "Bail Analysis" API (bail endpoint)
def bail_analysis(query):
    try:
        response = requests.post("https://aaronanoronha-haha.hf.space/bail", json={"topic": query})
        data = json.loads(response.text)
        return data.get("response", "No response found")
    except Exception as e:
        return f"Error: {e}"

# Create a Gradio Blocks interface with tabs for each API
with gr.Blocks() as demo:
    gr.Markdown("# Legal AI Assistant")
    with gr.Tabs():
        with gr.TabItem("Previous Cases"):
            input_text = gr.Textbox(lines=3, placeholder="Enter your query...", label="Query")
            output_text = gr.Textbox(lines=10, label="Response")
            gr.Button("Submit").click(fn=previous_cases, inputs=input_text, outputs=output_text)
            
        with gr.TabItem("Law Navigation"):
            input_text2 = gr.Textbox(lines=3, placeholder="Enter your query...", label="Query")
            output_text2 = gr.Textbox(lines=10, label="Response")
            gr.Button("Submit").click(fn=law_navigation, inputs=input_text2, outputs=output_text2)
            
        with gr.TabItem("Judgment Prediction"):
            input_text3 = gr.Textbox(lines=3, placeholder="Enter your query...", label="Query")
            output_text3 = gr.Textbox(lines=10, label="Response")
            gr.Button("Submit").click(fn=judgment_prediction, inputs=input_text3, outputs=output_text3)
            
        with gr.TabItem("Bail Analysis"):
            input_text4 = gr.Textbox(lines=3, placeholder="Enter your query...", label="Query")
            output_text4 = gr.Textbox(lines=10, label="Response")
            gr.Button("Submit").click(fn=bail_analysis, inputs=input_text4, outputs=output_text4)

demo.launch()