adrienbrdne commited on
Commit
daafcf8
·
verified ·
1 Parent(s): 15270ef

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +86 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+
5
+ # --- API Configuration ---
6
+ API_URL = "https://adrienbrdne-fastapi-kig.hf.space/"
7
+ ENDPOINT = f"{API_URL}/generate-key-issues" # API endpoint name remains unchanged
8
+
9
+ # --- Streamlit Interface ---
10
+ st.set_page_config(page_title="Problematic Generator", layout="wide")
11
+ st.title("Generate Problematics from Query")
12
+
13
+ # Input field for the user query
14
+ user_query = st.text_input(
15
+ "Enter your query here:",
16
+ placeholder="Example: deploying edge computing for real-time AI-driven traffic management systems in smart cities"
17
+ )
18
+
19
+ # Button to submit the query
20
+ if st.button("Generate Problematics"):
21
+ if user_query: # Check if the user entered something
22
+ st.info(f"Sending query to API: {ENDPOINT}")
23
+ st.write(f"Query: \"{user_query}\"")
24
+
25
+ # Prepare data for the POST request
26
+ data = {"query": user_query}
27
+
28
+ try:
29
+ # Show a loading spinner during the API call
30
+ with st.spinner("Calling API to generate problematics..."):
31
+ response = requests.post(ENDPOINT, json=data, timeout=60) # Added a timeout
32
+
33
+ # Check the response status
34
+ if response.status_code == 200:
35
+ st.success("Response received successfully!")
36
+ result = response.json()
37
+
38
+ # Check if 'key_issues' key exists and is a list
39
+ if 'key_issues' in result and isinstance(result['key_issues'], list):
40
+ # Convert the 'key_issues' list to a Pandas DataFrame
41
+ df = pd.DataFrame(result['key_issues'])
42
+
43
+ # Remove the 'id' column if it exists
44
+ if 'id' in df.columns:
45
+ df_display = df.drop(columns=['id'])
46
+ else:
47
+ st.warning("Column 'id' was not found in the received data.")
48
+ df_display = df
49
+
50
+ # Display the DataFrame
51
+ st.subheader("Generated Problematics (DataFrame):")
52
+ st.dataframe(df_display, use_container_width=True) # Display dataframe with full container width
53
+
54
+ # Optional: Display raw JSON response for verification
55
+ # st.subheader("Raw JSON Response Received:")
56
+ # st.json(result)
57
+
58
+ else:
59
+ st.error("API response does not contain the expected 'key_issues' key or it is not a list.")
60
+ st.json(result) # Display the received response for debugging
61
+
62
+ else:
63
+ # Display an error if status is not 200
64
+ st.error(f"API Call Error: Status {response.status_code}")
65
+ try:
66
+ # Try to display the API error message if it's JSON
67
+ error_details = response.json()
68
+ st.json(error_details)
69
+ except requests.exceptions.JSONDecodeError:
70
+ # Otherwise, display the raw text response
71
+ st.text(response.text)
72
+
73
+ except requests.exceptions.RequestException as e:
74
+ # Handle connection or timeout errors
75
+ st.error(f"API Connection Error: {e}")
76
+ except Exception as e:
77
+ # Handle any other unexpected errors
78
+ st.error(f"An unexpected error occurred: {e}")
79
+
80
+ else:
81
+ # Message if the user clicks the button without entering a query
82
+ st.warning("Please enter a query before generating.")
83
+
84
+ # Initial instructions
85
+ else:
86
+ st.info("Enter a query in the field above and click 'Generate Problematics' to query the API.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ requests
3
+ pandas