JamalAG commited on
Commit
a78c002
1 Parent(s): e3e2eaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -1,39 +1,43 @@
1
  import streamlit as st
2
  from langchain.llms import HuggingFaceHub
3
- from langchain.chains import LLMChain
4
- from langchain.prompts import PromptTemplate
5
 
6
- # Function to return the response
7
  def generate_answer(query):
8
  llm = HuggingFaceHub(
9
- repo_id="google/flan-t5-xxl",
10
- model_kwargs={"temperature": 0.7, "max_length": 64, "max_new_tokens": 512}
11
  )
12
-
13
- template = """Question: {query}
14
-
15
- Answer: Let's give medical advices in kind way."""
16
-
17
- prompt = PromptTemplate(template=template, input_variables=["query"])
18
- llm_chain = LLMChain(prompt=prompt, llm=llm)
19
- result = llm_chain.run(query)
20
  return result
 
 
 
 
 
21
 
22
- # App UI starts here
23
- st.set_page_config(page_title="Doctor Assistant Demo", page_icon=":robot:")
24
- st.header("Doctor Assistant Demo")
25
 
26
- # Gets User Input
27
  def get_text():
28
  input_text = st.text_input("You: ", key="input")
29
  return input_text
30
 
 
31
  user_input = get_text()
32
  response = generate_answer(user_input)
33
 
34
  submit = st.button("Generate")
35
 
36
- # If the button clicked
37
  if submit:
38
- st.subheader("Doctor's Response:")
39
- st.write(response)
 
 
 
 
1
  import streamlit as st
2
  from langchain.llms import HuggingFaceHub
 
 
3
 
4
+ #Function to return the response
5
  def generate_answer(query):
6
  llm = HuggingFaceHub(
7
+ repo_id = "huggingfaceh4/zephyr-7b-alpha",
8
+ model_kwargs={"temperature": 0.5, "max_length": 64,"max_new_tokens":512}
9
  )
10
+ prompt = f"""
11
+ You are a doctor assistant trained to provide medical advice and support. Please respond with empathy and consider the patient's well-being.
12
+ </s>
13
+
14
+ {query}</s>
15
+
16
+ """
17
+ result = llm.predict(prompt)
18
  return result
19
+
20
+
21
+ #App UI starts here
22
+ st.set_page_config(page_title = "LangChain Demo", page_icon = ":robot:")
23
+ st.header("LangChain Demo")
24
 
 
 
 
25
 
26
+ #Gets User Input
27
  def get_text():
28
  input_text = st.text_input("You: ", key="input")
29
  return input_text
30
 
31
+
32
  user_input = get_text()
33
  response = generate_answer(user_input)
34
 
35
  submit = st.button("Generate")
36
 
37
+ #If the button clicked
38
  if submit:
39
+ st.subheader("Answer: ")
40
+ st.write(response)
41
+
42
+
43
+