meesamraza commited on
Commit
08231ff
·
verified ·
1 Parent(s): 0e9c64b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -30
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  from groq import Groq
3
  import streamlit as st
4
  from dotenv import load_dotenv
@@ -24,18 +24,15 @@ developer_topics = [
24
 
25
  # Function to fetch chatbot completion from Groq API
26
  def get_response(query):
27
- try:
28
- completion = client.chat.completions.create(
29
- model="llama-3.3-70b-versatile",
30
- messages=[{"role": "user", "content": query}],
31
- temperature=0.7,
32
- max_completion_tokens=2024,
33
- top_p=1,
34
- )
35
- response = completion.choices[0].message.content
36
- return response
37
- except Exception as e:
38
- return f"Error: {str(e)}"
39
 
40
  def main():
41
  st.title("Programming Developer Advisor Chatbot")
@@ -44,24 +41,17 @@ def main():
44
  topic = st.selectbox("Choose a programming topic", developer_topics)
45
  user_input = st.text_area("Or ask a programming-related question:", "")
46
 
47
- # Add a submit button to trigger the response
48
- submit_button = st.button("Submit")
 
 
 
 
49
 
50
- # If the user clicks the submit button, process the query
51
- if submit_button:
52
- if user_input:
53
- query = user_input
54
- # Check if the user input is related to a programming topic
55
- if any(topic.lower() in user_input.lower() for topic in developer_topics):
56
- response = get_response(query)
57
- st.write("### Response:")
58
- # Display the response with proper formatting, and if it is long, we can show it in a scrollable container
59
- st.markdown(f"#### Query: {query}")
60
- st.text_area("Response:", response, height=300)
61
- else:
62
- st.write("Sorry, I can only answer programming-related questions.")
63
- else:
64
- st.write("Please enter a programming-related question or choose a topic.")
65
 
66
  if __name__ == "__main__":
67
  main()
 
 
1
+ "import os
2
  from groq import Groq
3
  import streamlit as st
4
  from dotenv import load_dotenv
 
24
 
25
  # Function to fetch chatbot completion from Groq API
26
  def get_response(query):
27
+ completion = client.chat.completions.create(
28
+ model="llama-3.3-70b-versatile",
29
+ messages=[{"role": "user", "content": query}],
30
+ temperature=0.7,
31
+ max_completion_tokens=2024,
32
+ top_p=1,
33
+ )
34
+ response = completion.choices[0].message.content
35
+ return response
 
 
 
36
 
37
  def main():
38
  st.title("Programming Developer Advisor Chatbot")
 
41
  topic = st.selectbox("Choose a programming topic", developer_topics)
42
  user_input = st.text_area("Or ask a programming-related question:", "")
43
 
44
+ # If the user provides a query (not from audio), use that directly
45
+ if user_input:
46
+ query = user_input
47
+ response = get_response(query)
48
+ st.write("### Response:")
49
+ st.write(response)
50
 
51
+ # Handle unrelated queries
52
+ if user_input and not any(topic in user_input.lower() for topic in developer_topics):
53
+ st.write("Sorry, I can only answer programming-related questions.")
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  if __name__ == "__main__":
56
  main()
57
+ " add submit button and if the question is out of the relate the massges print other wise the output show the answer