zhaokeyao1 commited on
Commit ·
66877e4
1
Parent(s): 11a3976
Update space
Browse files- app.py +43 -2
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,6 +4,47 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
|
|
@@ -57,7 +98,7 @@ demo = gr.ChatInterface(
|
|
| 57 |
),
|
| 58 |
],
|
| 59 |
)
|
| 60 |
-
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
| 7 |
+
from new_chat import Conversation, ChatgptAPI
|
| 8 |
+
|
| 9 |
+
chat_api = ChatgptAPI()
|
| 10 |
+
|
| 11 |
+
def predict(system_input, password_input, user_in_file, user_input, conversation):
|
| 12 |
+
if password_input != '112233':
|
| 13 |
+
return [(None, "Wrong password!")], conversation, user_input
|
| 14 |
+
|
| 15 |
+
if conversation.is_initialized() == False:
|
| 16 |
+
conversation = Conversation(system_input, 5)
|
| 17 |
+
conversation = chat_api.get_single_round_completion(user_in_file, user_input, conversation)
|
| 18 |
+
return conversation, conversation, None
|
| 19 |
+
#_, conversation = chat_api.get_multi_round_completion(user_input, conversation)
|
| 20 |
+
#return conversation.get_history_messages(), conversation, None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def clear_history(conversation):
|
| 24 |
+
conversation.clear()
|
| 25 |
+
return None, conversation
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
with gr.Blocks(css="#chatbot{height:350px} .overflow-y-auto{height:600px}") as demo:
|
| 29 |
+
chatbot = gr.Chatbot(elem_id="chatbot")
|
| 30 |
+
conversation = gr.State(value=Conversation())
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
system_in_txt = gr.Textbox(lines=1, label="System role content:", placeholder="Enter system role content")
|
| 34 |
+
password_in_txt = gr.Textbox(lines=1, label="Password:", placeholder="Enter password")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
user_in_file = gr.File(label="Upload File")
|
| 38 |
+
user_in_txt = gr.Textbox(lines=3, label="User role content:", placeholder="Enter text...").style(container=False)
|
| 39 |
+
|
| 40 |
+
with gr.Row():
|
| 41 |
+
submit_button = gr.Button("Submit")
|
| 42 |
+
reset_button = gr.Button("Reset")
|
| 43 |
+
|
| 44 |
+
submit_button.click(predict, [system_in_txt, password_in_txt, user_in_file, user_in_txt, conversation], [chatbot, conversation, user_in_txt])
|
| 45 |
+
reset_button.click(clear_history, [conversation], [chatbot, conversation], queue=False)
|
| 46 |
+
|
| 47 |
+
'''
|
| 48 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 49 |
|
| 50 |
|
|
|
|
| 98 |
),
|
| 99 |
],
|
| 100 |
)
|
| 101 |
+
'''
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
| 104 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
huggingface_hub==0.22.2
|