crawled_data / app.py
Divyanshyadav007's picture
Update app.py
a74b6e2 verified
import gradio as gr
import pymongo
import json
# Load insights from JSON file
def greet(session_id, user_id, query, jurisdiction, work_area):
file=open('mydata.json', 'r')
insights = json.load(file)
message = None # Initialize message variable
# Search for the matching insight
for insight in insights:
if (insight.get('Title').lower() == query.lower() and
insight.get('Jurisdiction Insight').lower() == jurisdiction.lower() and
insight.get('Work Areas Art').lower() == work_area.lower()):
message = insight.get('Content')
break
# Prepare response data
if message is None:
response = {'rada_response': 'No matching insight found.'}
else:
response = {'rada_response': str(message)}
return response
# Create Gradio interface
demo = gr.Interface(
fn=greet,
inputs=[
gr.Textbox(label="Session ID"),
gr.Textbox(label="User ID"),
gr.Textbox(label="Query"),
gr.Textbox(label="Jurisdiction"),
gr.Textbox(label="Work Area")
],
outputs=gr.JSON(label="Generated JSON"),
)
demo.launch()