CenterFor commited on
Commit
56f5cc9
·
1 Parent(s): b43398a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
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
- with gr.Blocks() as demo:
30
- chatbot = gr.Chatbot()
31
- msg = gr.Textbox()
32
- flag = gr.Button("Flag")
33
 
34
- # Initialize HuggingFaceDatasetSaver
35
- HF_TOKEN = os.getenv('HF_TOKEN') # replace 'HF_TOKEN' with the name of your environment variable
36
- hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CenterFor/HeyJesus_Feedback")
 
 
37
 
38
- # This needs to be called at some point prior to the first call to hf_writer.flag()
39
- hf_writer.setup([chatbot, msg], "flagged_conversations")
 
 
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
- # We can choose which components to flag -- in this case, we'll flag all of them
62
- flag.click(lambda *args: hf_writer.flag(args), [chatbot, msg], None, preprocess=False)
 
 
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()