yhraje's picture
update app.py
68a23df verified
raw
history blame
1.52 kB
import requests
import gradio as gr
# API Configuration
api_key = "sk-6Ng7YDAkl0D5z20vAh7tPkmWn5hCTcZGIcl_wRiQ5NQ" # replace with your actual key
url = "http://localhost:7860/api/v1/run/30d9ce86-194f-44ba-a15a-f822c3ac4f57" # LangFlow endpoint
def query_langflow(user_input):
payload = {
"output_type": "chat",
"input_type": "chat",
"input_value": user_input
}
headers = {
"Content-Type": "application/json",
"x-api-key": api_key
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
# Adjust based on actual LangFlow response structure
if isinstance(data, dict):
return data.get("outputs", data)
return str(data)
except requests.exceptions.RequestException as e:
return f"❌ API request failed: {e}"
except ValueError as e:
return f"⚠️ Error parsing response: {e}"
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## πŸš€ LangFlow Chat with Gradio")
chatbot = gr.Chatbot()
msg = gr.Textbox(placeholder="Ask something...")
def chat(user_input, history):
response = query_langflow(user_input)
history.append((user_input, response))
return history, ""
msg.submit(chat, [msg, chatbot], [chatbot, msg])
# πŸš€ This will show BOTH: local URL + public .gradio.live URL
demo.launch(server_name="http://127.0.0.1:4040", server_port=7861, share=True)