Spaces:
No application file
No application file
Create frontend.py
Browse files- frontend.py +61 -0
frontend.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
load_dotenv()
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
import requests
|
6 |
+
import json
|
7 |
+
|
8 |
+
st.set_page_config(page_title="LangGraph Agent UI", layout="centered")
|
9 |
+
st.title("AI Chatbot Agents")
|
10 |
+
st.write("Create and Interact with the AI Agents!")
|
11 |
+
|
12 |
+
system_prompt = st.text_area(
|
13 |
+
"Define your AI Agent: ",
|
14 |
+
height=70,
|
15 |
+
placeholder="Type your system prompt here...",
|
16 |
+
value="You are a helpful AI assistant."
|
17 |
+
)
|
18 |
+
|
19 |
+
MODEL_NAMES_GROQ = ["llama-3.3-70b-versatile", "mixtral-8x7b-32768"]
|
20 |
+
selected_model = st.selectbox("Select Groq Model:", MODEL_NAMES_GROQ)
|
21 |
+
|
22 |
+
allow_web_search = st.checkbox("Allow Web Search")
|
23 |
+
|
24 |
+
user_query = st.text_area(
|
25 |
+
"Enter your query: ",
|
26 |
+
height=150,
|
27 |
+
placeholder="Ask Anything!"
|
28 |
+
)
|
29 |
+
|
30 |
+
API_URL = "http://127.0.0.1:9999/chat"
|
31 |
+
|
32 |
+
if st.button("Ask Agent!"):
|
33 |
+
if not user_query.strip():
|
34 |
+
st.error("Please enter a query!")
|
35 |
+
else:
|
36 |
+
try:
|
37 |
+
with st.spinner("Getting response..."):
|
38 |
+
payload = {
|
39 |
+
"model_name": selected_model,
|
40 |
+
"model_provider": "Groq",
|
41 |
+
"system_prompt": system_prompt,
|
42 |
+
"messages": [user_query],
|
43 |
+
"allow_search": allow_web_search
|
44 |
+
}
|
45 |
+
|
46 |
+
# Add debug output
|
47 |
+
st.write("Sending request with payload:", json.dumps(payload, indent=2))
|
48 |
+
|
49 |
+
response = requests.post(API_URL, json=payload, timeout=120)
|
50 |
+
|
51 |
+
if response.status_code == 200:
|
52 |
+
response_data = response.json()
|
53 |
+
st.subheader("Agent Response")
|
54 |
+
st.markdown(f"{response_data['response']}")
|
55 |
+
else:
|
56 |
+
st.error(f"Server error: {response.text}")
|
57 |
+
|
58 |
+
except requests.exceptions.ConnectionError:
|
59 |
+
st.error("Could not connect to the backend server. Please make sure it's running on port 9999.")
|
60 |
+
except Exception as e:
|
61 |
+
st.error(f"An error occurred: {str(e)}")
|