velmurugan1122 commited on
Commit
4eac7d7
·
1 Parent(s): 39775e7

created project

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from groq import Groq
3
+
4
+ # Initialize Groq client
5
+ client = Groq(api_key="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")
6
+
7
+ # Page configuration
8
+ st.set_page_config(page_title="Gastroenterology Chatbot", page_icon="🌟")
9
+
10
+ # Custom CSS for design improvements
11
+ st.markdown(
12
+ """
13
+ <style>
14
+ .chat-bubble {
15
+ padding: 10px;
16
+ border-radius: 10px;
17
+ margin-bottom: 10px;
18
+ }
19
+ .user-bubble {
20
+ background-color: #DCF8C6;
21
+ text-align: right;
22
+ }
23
+ .assistant-bubble {
24
+ background-color: #ECECEC;
25
+ text-align: left;
26
+ }
27
+ .icon {
28
+ font-size: 20px;
29
+ margin-right: 10px;
30
+ }
31
+ </style>
32
+ """,
33
+ unsafe_allow_html=True,
34
+ )
35
+
36
+ st.title("Gastroenterology Chatbot")
37
+
38
+ st.write("I am a highly knowledgeable and compassionate AI gastroenterology assistant. Ask me anything about digestive health!")
39
+
40
+ # Initialize chat history if not present
41
+ if "messages" not in st.session_state:
42
+ st.session_state.messages = [
43
+ {"role": "system", "content": "You are a highly knowledgeable and compassionate AI gastroenterology assistant. Your primary goal is to provide accurate, clear, and empathetic information and guidance related to digestive health. By offering evidence-based insights, encouraging wellness practices, and respecting user privacy, you empower individuals to make informed decisions about their digestive well-being while promoting responsible healthcare practices. Although you are not a substitute for a doctor or licensed healthcare provider, you create a safe, trustworthy, and supportive environment where users feel comfortable seeking and receiving information about their symptoms, treatments, and lifestyle changes that promote a healthy gut."}
44
+ ]
45
+
46
+ # User input
47
+ user_input = st.text_input("You:", "")
48
+ if user_input:
49
+ st.session_state.messages.append({"role": "user", "content": user_input})
50
+
51
+ try:
52
+ chat_completion = client.chat.completions.create(
53
+ messages=st.session_state.messages,
54
+ model="llama-3.3-70b-versatile",
55
+ )
56
+ response = chat_completion.choices[0].message.content
57
+
58
+
59
+ if "gastro" not in response.lower():
60
+ response = "💡 That question seems to be outside the field of gastroenterology. Let me help you with any digestive health-related concerns!"
61
+
62
+ st.session_state.messages.append({"role": "assistant", "content": response})
63
+ except Exception as e:
64
+ st.error(f"An error occurred: {e}")
65
+
66
+ # Display chat history
67
+ st.write("## Chat History")
68
+ for message in st.session_state.messages:
69
+ if message["role"] == "user":
70
+ st.markdown(f"<div class='chat-bubble user-bubble'><span class='icon'>👤</span>{message['content']}</div>", unsafe_allow_html=True)
71
+ elif message["role"] == "assistant":
72
+ st.markdown(f"<div class='chat-bubble assistant-bubble'><span class='icon'>🏥</span>{message['content']}</div>", unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ groq