Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
7 |
def generate_answer(query):
|
8 |
llm = HuggingFaceHub(
|
9 |
-
repo_id="
|
10 |
-
model_kwargs={"temperature": 0.
|
11 |
)
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
result =
|
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 |
-
#
|
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 |
-
#
|
37 |
if submit:
|
38 |
-
st.subheader("
|
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 |
+
|