Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
import random
|
| 4 |
+
import graphviz
|
| 5 |
+
|
| 6 |
+
# Initialize Streamlit secrets
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Initialize ChatGoogleGenerativeAI with your specific model and API key
|
| 10 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 11 |
+
|
| 12 |
+
# Define problem categories and corresponding flowchart templates or responses
|
| 13 |
+
problem_categories = {
|
| 14 |
+
"network issue": "Start -> Check cables -> Restart router -> Check connection -> End",
|
| 15 |
+
"software problem": "Start -> Check for updates -> Restart application -> Contact support -> End",
|
| 16 |
+
"hardware issue": "Start -> Check connections -> Test components -> Replace faulty part -> End",
|
| 17 |
+
"login problem": "Start -> Check credentials -> Reset password -> Verify account -> End",
|
| 18 |
+
"general inquiry": "Start -> Gather information -> Provide assistance -> End"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Function to generate flowchart response based on user input
|
| 22 |
+
def generate_flowchart(user_input):
|
| 23 |
+
user_input = user_input.strip().lower()
|
| 24 |
+
|
| 25 |
+
# Check for specific problem categories
|
| 26 |
+
for category, template in problem_categories.items():
|
| 27 |
+
if category in user_input:
|
| 28 |
+
return f"Flowchart for {category.capitalize()}:\n{template}"
|
| 29 |
+
|
| 30 |
+
# If no specific category matches, use general inquiry flowchart
|
| 31 |
+
return problem_categories["general inquiry"]
|
| 32 |
+
|
| 33 |
+
# Streamlit app setup
|
| 34 |
+
st.title("Problem Solver Bot")
|
| 35 |
+
|
| 36 |
+
# User input text area
|
| 37 |
+
user_input = st.text_area("You:", "")
|
| 38 |
+
|
| 39 |
+
# Button to generate flowchart
|
| 40 |
+
if st.button("Generate Flowchart"):
|
| 41 |
+
if user_input:
|
| 42 |
+
# Generate flowchart based on user input
|
| 43 |
+
flowchart = generate_flowchart(user_input)
|
| 44 |
+
|
| 45 |
+
# Display flowchart using graphviz
|
| 46 |
+
st.graphviz_chart(flowchart)
|
| 47 |
+
else:
|
| 48 |
+
st.warning("Please enter your problem description.")
|
| 49 |
+
|
| 50 |
+
# Additional information or footer
|
| 51 |
+
st.markdown("---")
|
| 52 |
+
st.markdown("Enter a problem description and click 'Generate Flowchart' to see the solution flowchart.")
|
| 53 |
+
|