Praneeth KVS commited on
Commit
4de29f2
·
verified ·
1 Parent(s): 0b29f8d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Agrichat-bot.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1x6nj6FVHwQDucH0LD-skTOqRwKkDuwCZ
8
+ """
9
+
10
+ !pip install -q -U google-generativeai
11
+
12
+ pip install gradio
13
+
14
+ import gradio as gr
15
+ import os
16
+ import google.generativeai as genai
17
+
18
+ import google.generativeai as genai
19
+ from google.colab import userdata
20
+
21
+ #GOOGLE_API_KEY=userdata.get('G-API_key2')
22
+ #genai.configure(api_key=GOOGLE_API_KEY)
23
+
24
+ def gemini_chat(message, history):
25
+ GOOGLE_API_KEY = 'AIzaSyBJeLAdQIoMkF8cHrNpCFrtb0iU_QAgk84'
26
+ genai.configure(api_key=GOOGLE_API_KEY)
27
+ model = genai.GenerativeModel('gemini-pro')
28
+ chat = model.start_chat()
29
+ prompt = 'Question :' + message + '- ' + 'If this Question is related to agriculture, farming, pests, agricultute practices, farmers, crops, crop management, soil, irrigation, various aspects of agriculture, pest control, weather forecasting, market prices, general farming queries, relevant stuff then consider the question as valid and generate answer(only the answer, not the description of what the instruction I have provided in about 30-40 words), otherwise reply that, I am sorry, but I cannot provide an answer to that question as it is inappropriate or not related to agriculture. One more point to remember is to make sure to be interactive, such as greeting the users if they say hi & introduce yourself & how can you help them with(related to farming & agriculture) but dont say that it is not related to agriculture only if the user is greeting or introducing, or say welcome if user says thank you etc. but make sure you never reveal that you are made using Gemini, if needed respond saying that contact author for more information)'
30
+ response = chat.send_message(prompt)
31
+ return response.text
32
+
33
+ iface = gr.ChatInterface(
34
+ fn=gemini_chat,
35
+ title='AGRI-CHAT : Your Personal AI powered Chatbot, built for Agriculture/Farming related queries',
36
+ chatbot=gr.Chatbot(height=200),
37
+ textbox=gr.Textbox(
38
+ placeholder="What's your question? Please type here!!",
39
+ scale=7
40
+ ),
41
+ retry_btn=None,
42
+ undo_btn=None,
43
+ clear_btn=None
44
+ )
45
+
46
+ if __name__ == '__main__':
47
+ iface.launch(debug=True)
48
+
49
+ #!git config --global credential.helper store
50
+
51
+ #!gradio deploy
52
+