krishanusinha20 commited on
Commit
36054cd
·
verified ·
1 Parent(s): 6ebf6d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -7,6 +7,7 @@ from datetime import timedelta
7
  from faker import Faker
8
  from langgraph.graph import StateGraph, START
9
  from typing import TypedDict, Optional
 
10
 
11
  # Set your OpenAI API key from environment variable
12
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -343,11 +344,18 @@ graph.add_edge("Query Optimization", "SQL Execution")
343
 
344
  compiled_pipeline = graph.compile()
345
 
346
- # ------------------ Example Execution ------------------
347
  def run_multi_agent_query(natural_language_query):
348
  result = compiled_pipeline.invoke({"sql_query": natural_language_query})
349
  return json.dumps(result.get("execution_result", {}), indent=2)
350
 
 
 
 
 
 
 
 
 
351
  if __name__ == "__main__":
352
- # For testing outside of Hugging Face Spaces
353
- print(run_multi_agent_query("Find the email_id of the top 5 customers who spent the most in 2024."))
 
7
  from faker import Faker
8
  from langgraph.graph import StateGraph, START
9
  from typing import TypedDict, Optional
10
+ import gradio as gr
11
 
12
  # Set your OpenAI API key from environment variable
13
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
344
 
345
  compiled_pipeline = graph.compile()
346
 
347
+ # ------------------ Gradio Interface ------------------
348
  def run_multi_agent_query(natural_language_query):
349
  result = compiled_pipeline.invoke({"sql_query": natural_language_query})
350
  return json.dumps(result.get("execution_result", {}), indent=2)
351
 
352
+ iface = gr.Interface(
353
+ fn=run_multi_agent_query,
354
+ inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
355
+ outputs="text",
356
+ title="Multi-Agent SQL Generator",
357
+ description="Enter a natural language query to generate and execute a SQL query."
358
+ )
359
+
360
  if __name__ == "__main__":
361
+ iface.launch()