YathinManugula commited on
Commit
ad259e2
·
1 Parent(s): 8025763

Upload copy_of_chatbot_using_palm2.py

Browse files
Files changed (1) hide show
  1. copy_of_chatbot_using_palm2.py +41 -0
copy_of_chatbot_using_palm2.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/1SiwltrRkFf5EIhLLbj9GISjb8HmDJYw3
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
+
16
+ palm.configure(api_key='AIzaSyC2lkfp2czLhE0sFZ9I8Rm6bRQyBMuKexs')
17
+
18
+ models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
19
+ model = models[0].name
20
+
21
+ #def get_text_response(user_message,history):
22
+ # response = palm.chat(messages=user_message)
23
+ # return response.last
24
+
25
+ #demo = gr.ChatInterface(get_text_response, examples=["How are you doing?","What are your interests?","Which places do you like to visit?"])
26
+
27
+ def get_text_response(user_message,history):
28
+ completion = palm.generate_text(
29
+ model=model,
30
+ prompt=user_message,
31
+ temperature=0.25,
32
+ # temperature=0 >> more deterministic results // temperature=1 >> more randomness
33
+ max_output_tokens=100
34
+ # maximum length of response
35
+ )
36
+ return completion.result
37
+
38
+ demo = gr.ChatInterface(get_text_response, examples=["How are you doing?","What are your interests?","Which places do you like to visit?"])
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()