aditijuluri commited on
Commit
7cd192c
·
verified ·
1 Parent(s): 3bbd94c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -74,23 +74,24 @@ with gr.Blocks() as demo:
74
  "hey there! its RecoNext, your favorite binge buddy! get started by telling me you age, preferred genre, and past tv shows or movies you have liked!"
75
  )
76
  return [("", greeting)], [{"role": "assistant", "content": greeting}]
77
-
78
- # Chat handler
79
- def user_message(message, history):
80
- bot_response = respond(message, history)
81
- history.append({"role": "user", "content": message})
82
- history.append({"role": "assistant", "content": bot_response})
83
-
84
- # Format history for display in Chatbot
85
- display = []
86
- for i in range(1, len(history), 2):
87
- display.append((history[i-1]["content"], history[i]["content"]))
88
- return display, history
89
-
90
- # Load initial greeting
91
- demo.load(startup, outputs=[chatbot, state])
92
-
93
- # Respond to user input
94
- msg.submit(fn=user_message, inputs=[msg, state], outputs=[chatbot, state])
95
-
96
- demo.launch()
 
 
74
  "hey there! its RecoNext, your favorite binge buddy! get started by telling me you age, preferred genre, and past tv shows or movies you have liked!"
75
  )
76
  return [("", greeting)], [{"role": "assistant", "content": greeting}]
77
+ def respond(message, history):
78
+ best_next_watch = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
79
+ print(best_next_watch)
80
+ str_watch_chunks = "\n".join(best_next_watch)
81
+ messages = [
82
+ {"role":"system",
83
+ "content": "You are a gen-z helpful chatbot that helps teenagers find their next best watch, speak in gen-z terms and be natural. You should answer the users question based on " + str_watch_chunks + " ."
84
+ }
85
+ ]
86
+ if history:
87
+ messages.extend(history)
88
+ messages.append(
89
+ {'role':'user',
90
+ 'content':message}
91
+ )
92
+ response = client.chat_completion(
93
+ messages, max_tokens = 300, temperature=1.3, top_p=0.6
94
+ )
95
+ return response['choices'][0]['message']['content'].strip()
96
+ chatbot = gr.ChatInterface(respond, type="messages")
97
+ chatbot.launch()