Unukonda commited on
Commit
cd41fd4
1 Parent(s): 37c30f3

Upload copy_of_chatbot_using_palm2.py

Browse files
Files changed (1) hide show
  1. copy_of_chatbot_using_palm2.py +42 -0
copy_of_chatbot_using_palm2.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Copy of Chatbot Using Palm2.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1LmFbsKVPTLlpcFU1oiC0wTfgE4mxeMs9
8
+ """
9
+
10
+ !pip install -q google-generativeai
11
+ !pip install gradio
12
+
13
+ import google.generativeai as palm
14
+ import gradio as gr
15
+ from google.colab import userdata
16
+
17
+ palm.configure(api_key=userdata.get('API_KEY'))
18
+
19
+ models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
20
+ model = models[0].name
21
+
22
+ #def get_text_response(user_message,history):
23
+ # response = palm.chat(messages=user_message)
24
+ # return response.last
25
+
26
+ #demo = gr.ChatInterface(get_text_response, examples=["How are you doing?","What are your interests?","Which places do you like to visit?"])
27
+
28
+ def get_text_response(user_message,history):
29
+ completion = palm.generate_text(
30
+ model=model,
31
+ prompt=user_message,
32
+ temperature=0.25,
33
+ # temperature=0 >> more deterministic results // temperature=1 >> more randomness
34
+ max_output_tokens=100
35
+ # maximum length of response
36
+ )
37
+ return completion.result
38
+
39
+ demo = gr.ChatInterface(get_text_response, examples=["How are you doing?","What are your interests?","Which places do you like to visit?"])
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch()