Spaces:
Sleeping
Sleeping
Commit
·
567c17c
1
Parent(s):
44dfb88
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,25 +4,33 @@ import os
|
|
| 4 |
|
| 5 |
client = hf_hub.InferenceClient(token = os.environ['HUGGINGFACEHUB_API_TOKEN'])
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
Chatbot :'''
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
'''
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
return prompt
|
| 28 |
|
|
|
|
| 4 |
|
| 5 |
client = hf_hub.InferenceClient(token = os.environ['HUGGINGFACEHUB_API_TOKEN'])
|
| 6 |
|
| 7 |
+
def create_chat_summary(history):
|
| 8 |
+
context = '''
|
| 9 |
+
Please summarize following conversation so that it become context to further conversation:
|
| 10 |
|
| 11 |
+
Chatbot: I am a chemistry professor. I help student to understand chemistry.
|
| 12 |
+
'''
|
| 13 |
+
for ques, ans in history:
|
| 14 |
+
context += f'''
|
| 15 |
+
Human : {ques}
|
| 16 |
+
Chatbot : {ans}
|
| 17 |
+
'''
|
| 18 |
|
| 19 |
+
return context
|
|
|
|
| 20 |
|
| 21 |
+
def create_prompt(question, history):
|
| 22 |
+
context_prompt = create_chat_summary(history)
|
| 23 |
+
context = client.text_generation(prompt = context_prompt, model = 'google/flan-t5-xxl')
|
|
|
|
| 24 |
|
| 25 |
+
prompt = f'''
|
| 26 |
+
You are a good chatbot that talks with human based on following context:
|
| 27 |
|
| 28 |
+
Context :
|
| 29 |
+
{context}
|
| 30 |
|
| 31 |
+
Human : {question}
|
| 32 |
+
Chatbot :
|
| 33 |
+
'''
|
| 34 |
|
| 35 |
return prompt
|
| 36 |
|