ashkunwar commited on
Commit
5a6768b
·
1 Parent(s): 6ea8c2c

initial push

Browse files
Files changed (5) hide show
  1. .gitignore +6 -1
  2. .python-version +1 -0
  3. .streamlit/config.toml +13 -0
  4. app.py +32 -6
  5. requirements.txt +15 -14
.gitignore CHANGED
@@ -1,6 +1,11 @@
1
  # Environment variables
2
  .env
3
- .toml
 
 
 
 
 
4
  # Python
5
  __pycache__/
6
  *.py[cod]
 
1
  # Environment variables
2
  .env
3
+ .env.local
4
+ .env.production
5
+
6
+ # Streamlit secrets (keep template, exclude actual secrets)
7
+ .streamlit/secrets.toml
8
+
9
  # Python
10
  __pycache__/
11
  *.py[cod]
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.9
.streamlit/config.toml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [server]
2
+ headless = true
3
+ enableCORS = false
4
+ enableXsrfProtection = false
5
+
6
+ [browser]
7
+ gatherUsageStats = false
8
+
9
+ [theme]
10
+ primaryColor = "#667eea"
11
+ backgroundColor = "#ffffff"
12
+ secondaryBackgroundColor = "#f0f2f6"
13
+ textColor = "#262730"
app.py CHANGED
@@ -23,17 +23,30 @@ logging.basicConfig(level=logging.INFO)
23
  logger = logging.getLogger(__name__)
24
 
25
  try:
26
- if 'GROQ_API_KEY' not in os.environ:
 
 
 
 
27
  st.error("⚠️ GROQ_API_KEY not found!")
28
- st.info("Please add GROQ_API_KEY to your .env file")
 
 
 
 
 
 
 
29
  st.code("""
30
  # In .env file:
31
  GROQ_API_KEY=your_groq_api_key_here
32
  """)
33
  st.stop()
 
 
34
  except Exception as e:
35
  st.error(f"⚠️ Error accessing API key: {e}")
36
- st.error("Please check your .env file or environment variables")
37
  st.stop()
38
 
39
  try:
@@ -108,10 +121,23 @@ def load_sample_tickets():
108
  tickets_data = json.load(f)
109
  return [Ticket(**ticket_data) for ticket_data in tickets_data]
110
  except FileNotFoundError:
111
- st.error(" sample_tickets.json not found")
112
- return []
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  except Exception as e:
114
- st.error(f"❌ Error loading sample tickets: {e}")
115
  return []
116
 
117
  async def classify_tickets_async(classifier, tickets):
 
23
  logger = logging.getLogger(__name__)
24
 
25
  try:
26
+ # Try Streamlit Cloud secrets first, then fall back to .env
27
+ if hasattr(st, 'secrets') and 'GROQ_API_KEY' in st.secrets:
28
+ os.environ['GROQ_API_KEY'] = st.secrets['GROQ_API_KEY']
29
+ st.success("🔑 API key loaded from Streamlit Cloud secrets")
30
+ elif 'GROQ_API_KEY' not in os.environ:
31
  st.error("⚠️ GROQ_API_KEY not found!")
32
+ st.info("**For Streamlit Cloud deployment:**")
33
+ st.info("Add your API key in the Streamlit Cloud app settings > Secrets tab")
34
+ st.code("""
35
+ # In Streamlit Cloud Secrets:
36
+ GROQ_API_KEY = "your_groq_api_key_here"
37
+ """)
38
+ st.info("**For local development:**")
39
+ st.info("Add GROQ_API_KEY to your .env file")
40
  st.code("""
41
  # In .env file:
42
  GROQ_API_KEY=your_groq_api_key_here
43
  """)
44
  st.stop()
45
+ else:
46
+ st.success("🔑 API key loaded from environment")
47
  except Exception as e:
48
  st.error(f"⚠️ Error accessing API key: {e}")
49
+ st.error("Please check your configuration")
50
  st.stop()
51
 
52
  try:
 
121
  tickets_data = json.load(f)
122
  return [Ticket(**ticket_data) for ticket_data in tickets_data]
123
  except FileNotFoundError:
124
+ st.warning("📋 Sample tickets file not found. Using demo data for cloud deployment.")
125
+ # Create minimal demo data for cloud deployment
126
+ demo_tickets = [
127
+ {
128
+ "id": "DEMO-001",
129
+ "subject": "Demo ticket - Connection issue",
130
+ "body": "This is a demo ticket showing connection problems with our data source."
131
+ },
132
+ {
133
+ "id": "DEMO-002",
134
+ "subject": "Demo ticket - API question",
135
+ "body": "This is a demo ticket asking about API usage and documentation."
136
+ }
137
+ ]
138
+ return [Ticket(**ticket_data) for ticket_data in demo_tickets]
139
  except Exception as e:
140
+ st.error(f"❌ Error loading tickets: {e}")
141
  return []
142
 
143
  async def classify_tickets_async(classifier, tickets):
requirements.txt CHANGED
@@ -1,14 +1,15 @@
1
- streamlit==1.28.1
2
- groq==0.4.1
3
- pydantic==2.5.0
4
- python-dotenv==1.0.0
5
- httpx==0.25.2
6
- requests==2.31.0
7
- aiohttp==3.9.0
8
- beautifulsoup4==4.12.2
9
- numpy==1.24.3
10
- sentence-transformers==2.2.2
11
- scikit-learn==1.3.0
12
- lxml==4.9.3
13
- pandas==2.0.3
14
- plotly==5.17.0
 
 
1
+ streamlit>=1.28.0
2
+ groq>=0.4.0
3
+ pydantic>=2.5.0,<3.0.0
4
+ python-dotenv>=1.0.0
5
+ httpx>=0.25.0
6
+ requests>=2.31.0
7
+ aiohttp>=3.9.0
8
+ beautifulsoup4>=4.12.0
9
+ numpy>=1.24.0,<2.0.0
10
+ sentence-transformers>=2.2.0
11
+ scikit-learn>=1.3.0
12
+ lxml>=4.9.0
13
+ pandas>=2.0.0,<3.0.0
14
+ plotly>=5.17.0
15
+ asyncio-compat>=0.1.2