peterkros commited on
Commit
2194f61
·
verified ·
1 Parent(s): 2288685

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -39,6 +39,18 @@ def generate_response(selected_question):
39
  temperature=0.7,
40
  ).choices[0].message['content'].strip()
41
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  topics_str = "Topic analysis not available"
43
 
44
  # Adjusted to return a list of tuples as expected by the Chatbot component
@@ -47,8 +59,12 @@ def generate_response(selected_question):
47
  except Exception as e:
48
  new_response = (None, f"Error generating response: {e}")
49
  chat_history.append(new_response)
 
50
 
51
- return chat_history
 
 
 
52
 
53
  with gr.Blocks() as demo:
54
  gr.Markdown(
@@ -70,16 +86,20 @@ with gr.Blocks() as demo:
70
  txt = gr.Textbox(scale=4, show_label=False, placeholder="Select Question", container=False, interactive=False) # Adjust based on need
71
  btn = gr.Button("Submit")
72
 
73
- btn.click(fn=generate_response, inputs=[txt], outputs=chatbot)
74
-
75
- examples = [
76
- ["What are the basic requirements to become an airforce pilot?"],
77
- ["How long does it take to train as an airforce pilot?"],
78
- ["Can you describe a day in the life of an airforce pilot?"]
79
- ]
80
- gr.Examples(examples, inputs=[txt], outputs=[chatbot], label="Select Question")
 
 
 
 
81
 
82
  chatbot.like(print_like_dislike, None, None)
83
 
84
  if __name__ == "__main__":
85
- demo.launch()
 
39
  temperature=0.7,
40
  ).choices[0].message['content'].strip()
41
 
42
+ follow_up_prompt = f"Based on the following response, suggest three follow-up questions: {response}"
43
+ follow_up_response = openai.ChatCompletion.create(
44
+ model="gpt-3.5-turbo",
45
+ messages=[
46
+ {"role": "system", "content": "You are a friendly and helpful chatbot."},
47
+ {"role": "user", "content": follow_up_prompt}
48
+ ],
49
+ max_tokens=100,
50
+ temperature=0.7,
51
+ ).choices[0].message['content'].strip()
52
+
53
+ follow_up_questions = follow_up_response.split('\n')
54
  topics_str = "Topic analysis not available"
55
 
56
  # Adjusted to return a list of tuples as expected by the Chatbot component
 
59
  except Exception as e:
60
  new_response = (None, f"Error generating response: {e}")
61
  chat_history.append(new_response)
62
+ follow_up_questions = []
63
 
64
+ return chat_history, follow_up_questions
65
+
66
+ def update_examples(follow_up_questions):
67
+ return gr.Examples.update(examples=[[q] for q in follow_up_questions])
68
 
69
  with gr.Blocks() as demo:
70
  gr.Markdown(
 
86
  txt = gr.Textbox(scale=4, show_label=False, placeholder="Select Question", container=False, interactive=False) # Adjust based on need
87
  btn = gr.Button("Submit")
88
 
89
+ btn.click(fn=generate_response, inputs=[txt], outputs=[chatbot, 'examples'])
90
+
91
+ examples_component = gr.Examples(
92
+ examples=[
93
+ ["What are the basic requirements to become an airforce pilot?"],
94
+ ["How long does it take to train as an airforce pilot?"],
95
+ ["Can you describe a day in the life of an airforce pilot?"]
96
+ ],
97
+ inputs=[txt],
98
+ outputs=[chatbot],
99
+ label="Select Question"
100
+ )
101
 
102
  chatbot.like(print_like_dislike, None, None)
103
 
104
  if __name__ == "__main__":
105
+ demo.launch()