JohnAlexander23 commited on
Commit
ffb99d3
1 Parent(s): 9260a76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -2,12 +2,16 @@ import streamlit as st
2
  import os
3
  from groq import Groq # Ensure Groq library supports this usage
4
  from dotenv import load_dotenv
 
 
5
  load_dotenv()
6
 
7
- os.getenv("GROQ_API_KEY")
 
8
 
 
9
  def fetch_response(user_input):
10
- client = Groq(api_key=os.getenv("GROQ_API_KEY"))
11
  chat_completion = client.chat.completions.create(
12
  messages=[
13
  {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper expamples to help the user. Try to mention references or provide citations to make it more detail oriented."},
@@ -17,19 +21,16 @@ def fetch_response(user_input):
17
  stream=False
18
  )
19
  return chat_completion.choices[0].message.content
20
- # for each in chat_completion:
21
- # yield (each.choices[0].delta.content)
22
- # #end=""
23
-
24
 
25
- def fetch_response(text_input):
26
- # Implement your function to fetch response here
27
- return "Response: " + text_input # For demonstration purposes
28
-
29
- st.title("Fastest AI Chatbot By DL Titan")
30
  st.write("Ask a question and get a response.")
31
 
32
- text_input = st.text_input("Enter your question here:")
33
- if st.button("Submit"):
34
- response = fetch_response(text_input)
35
- st.write(response)
 
 
 
 
 
2
  import os
3
  from groq import Groq # Ensure Groq library supports this usage
4
  from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
  load_dotenv()
8
 
9
+ # Retrieve Groq API key from environment variables
10
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
11
 
12
+ # Define function to fetch response
13
  def fetch_response(user_input):
14
+ client = Groq(api_key=GROQ_API_KEY)
15
  chat_completion = client.chat.completions.create(
16
  messages=[
17
  {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper expamples to help the user. Try to mention references or provide citations to make it more detail oriented."},
 
21
  stream=False
22
  )
23
  return chat_completion.choices[0].message.content
 
 
 
 
24
 
25
+ # Streamlit app
26
+ st.title("Fastest AI Chatbot By DL Titans")
 
 
 
27
  st.write("Ask a question and get a response.")
28
 
29
+ # Text input for user's question
30
+ user_input = st.text_input("Enter your question here:")
31
+
32
+ # Button to trigger response
33
+ if st.button("Get Response"):
34
+ # Fetch and display response
35
+ response = fetch_response(user_input)
36
+ st.write("Response:", response)