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()