Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
| 3 |
-
import os
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
from langchain.prompts.chat import (
|
| 6 |
ChatPromptTemplate,
|
|
@@ -8,6 +7,7 @@ from langchain.prompts.chat import (
|
|
| 8 |
HumanMessagePromptTemplate,
|
| 9 |
)
|
| 10 |
from langchain.schema import HumanMessage, SystemMessage
|
|
|
|
| 11 |
|
| 12 |
# Initialize the chat model
|
| 13 |
chat = ChatOpenAI(model="gpt-3.5-turbo-16k")
|
|
@@ -26,17 +26,19 @@ chat_prompt = ChatPromptTemplate.from_messages(
|
|
| 26 |
[system_message_prompt, human_message_prompt]
|
| 27 |
)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
msg = gr.Textbox()
|
| 32 |
-
flag = gr.Button("Flag")
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def user(user_message, history):
|
| 42 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
|
@@ -58,8 +60,10 @@ with gr.Blocks() as demo:
|
|
| 58 |
)
|
| 59 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
flag
|
|
|
|
|
|
|
| 63 |
|
| 64 |
demo.queue()
|
| 65 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
|
|
|
| 3 |
from langchain.chat_models import ChatOpenAI
|
| 4 |
from langchain.prompts.chat import (
|
| 5 |
ChatPromptTemplate,
|
|
|
|
| 7 |
HumanMessagePromptTemplate,
|
| 8 |
)
|
| 9 |
from langchain.schema import HumanMessage, SystemMessage
|
| 10 |
+
from gradio import HuggingFaceLogger
|
| 11 |
|
| 12 |
# Initialize the chat model
|
| 13 |
chat = ChatOpenAI(model="gpt-3.5-turbo-16k")
|
|
|
|
| 26 |
[system_message_prompt, human_message_prompt]
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Setup HuggingFace flagging callback
|
| 30 |
+
hf_flagger = HuggingFaceLogger("CenterFor/HeyJesus_Feedback", api_key=HF_TOKEN)
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Define examples
|
| 33 |
+
examples = [
|
| 34 |
+
["Who is Michael of Nebadon?"],
|
| 35 |
+
["What is Nebadon?"],
|
| 36 |
+
]
|
| 37 |
|
| 38 |
+
with gr.Blocks(examples=examples) as demo:
|
| 39 |
+
chatbot = gr.Chatbot()
|
| 40 |
+
msg = gr.Textbox()
|
| 41 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 42 |
|
| 43 |
def user(user_message, history):
|
| 44 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
|
|
|
| 60 |
)
|
| 61 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 62 |
|
| 63 |
+
# Flagging button
|
| 64 |
+
flag = gr.Button('Flag')
|
| 65 |
+
hf_flagger.setup([chatbot, msg], "flagged_conversations")
|
| 66 |
+
flag.click(lambda: hf_flagger.flag([chatbot, msg]), [chatbot, msg], None, preprocess=False)
|
| 67 |
|
| 68 |
demo.queue()
|
| 69 |
demo.launch()
|