Spaces:
Runtime error
Runtime error
File size: 1,519 Bytes
d5f12c1 fdfaede 02ab95a fdfaede e666bbb 02ab95a e666bbb d5f12c1 02ab95a e666bbb 02ab95a e666bbb 02ab95a e666bbb 02ab95a 58d578b | 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 | 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="0.0.0.0", server_port=7865,share=True , ssr_mode=False)
|