meraj12 commited on
Commit
088f6f1
·
verified ·
1 Parent(s): 14f8ada

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -2,8 +2,14 @@
2
  import streamlit as st
3
  import numpy as np
4
  import faiss
 
5
  from sentence_transformers import SentenceTransformer
6
  import requests
 
 
 
 
 
7
 
8
  st.set_page_config(page_title="Meraj Graphics Assistant")
9
 
@@ -25,10 +31,10 @@ def search(query, top_k=3):
25
  return "\n".join(results)
26
 
27
  # Call Groq API
28
- def query_groq(context, question, api_key):
29
  url = "https://api.groq.com/openai/v1/chat/completions"
30
  headers = {
31
- "Authorization": f"Bearer {api_key}",
32
  "Content-Type": "application/json"
33
  }
34
  data = {
@@ -45,14 +51,15 @@ def query_groq(context, question, api_key):
45
  st.title("📋 Meraj Graphics Chat Assistant")
46
 
47
  question = st.text_input("Ask something about our services:")
48
- groq_key = st.text_input("Groq API Key", type="password")
49
 
50
  if st.button("Get Answer"):
51
- if not question or not groq_key:
52
- st.warning("Please provide both question and API key.")
 
 
53
  else:
54
  with st.spinner("Searching..."):
55
  context = search(question)
56
- answer = query_groq(context, question, groq_key)
57
  st.success("Answer:")
58
  st.write(answer)
 
2
  import streamlit as st
3
  import numpy as np
4
  import faiss
5
+ import os
6
  from sentence_transformers import SentenceTransformer
7
  import requests
8
+ from dotenv import load_dotenv
9
+
10
+ # Load environment variables
11
+ load_dotenv()
12
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
13
 
14
  st.set_page_config(page_title="Meraj Graphics Assistant")
15
 
 
31
  return "\n".join(results)
32
 
33
  # Call Groq API
34
+ def query_groq(context, question):
35
  url = "https://api.groq.com/openai/v1/chat/completions"
36
  headers = {
37
+ "Authorization": f"Bearer {GROQ_API_KEY}",
38
  "Content-Type": "application/json"
39
  }
40
  data = {
 
51
  st.title("📋 Meraj Graphics Chat Assistant")
52
 
53
  question = st.text_input("Ask something about our services:")
 
54
 
55
  if st.button("Get Answer"):
56
+ if not question:
57
+ st.warning("Please enter a question.")
58
+ elif not GROQ_API_KEY:
59
+ st.error("API key not found. Please set GROQ_API_KEY in your environment.")
60
  else:
61
  with st.spinner("Searching..."):
62
  context = search(question)
63
+ answer = query_groq(context, question)
64
  st.success("Answer:")
65
  st.write(answer)