Nilesh Ranjan Pal commited on
Commit
3fd3394
·
1 Parent(s): fe3f1c4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.chains import LLMChain
3
+ from langchain.prompts import PromptTemplate
4
+ from langchain.llms import OpenAI
5
+
6
+ os.environ['OPENAI_API_KEY'] = "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"
7
+ llm = OpenAI(temperature=0.6)
8
+
9
+ prompt_template_name = PromptTemplate(
10
+ input_variables=['symptoms'],
11
+ template="What Diseases are associated with {symptoms}? Mention one disease only by its name."
12
+ )
13
+ prompt_template_coping_strategies = PromptTemplate(
14
+ input_variables=['response'],
15
+ template="What are coping strategies for dealing with {response}? Write 3 strategies only."
16
+ )
17
+ prompt_template_books = PromptTemplate(
18
+ input_variables=['disease'],
19
+ template="What are books one should read probably having {disease} to know more about? Write 3 books only."
20
+ )
21
+
22
+ chain_name = LLMChain(llm=llm, prompt=prompt_template_name)
23
+ chain_coping_strategies = LLMChain(llm=llm, prompt=prompt_template_coping_strategies)
24
+ chain_books = LLMChain(llm=llm, prompt=prompt_template_books)
25
+
26
+ def get_disease_and_strategies(symptoms):
27
+ disease_response = chain_name.run(symptoms)
28
+ disease = disease_response
29
+
30
+ coping_strategies_response = chain_coping_strategies.run(disease)
31
+ coping_strategies = coping_strategies_response
32
+
33
+ books_response = chain_books.run(disease)
34
+ books = books_response
35
+
36
+ return {
37
+ 'Disease': disease,
38
+ 'Coping Strategies': coping_strategies,
39
+ 'Books': books
40
+ }
41
+
42
+ def main():
43
+ st.title("Health Chatbot")
44
+ st.write("Enter your symptoms and get health information:")
45
+
46
+ user_input = st.text_input("Enter Symptoms:")
47
+
48
+ if st.button("Submit"):
49
+ if user_input.strip().lower() == 'exit':
50
+ st.write("Thank you for using the Health Chatbot. Goodbye!")
51
+ else:
52
+ output = get_disease_and_strategies(user_input)
53
+ response = f"Health Information:\n\nDisease: {output['Disease']}\n\nCoping Strategies: {output['Coping Strategies']}\n\nBooks: {output['Books']}"
54
+ st.write(response)
55
+
56
+ if __name__ == '__main__':
57
+ main()