File size: 2,121 Bytes
4de29f2
 
 
 
 
 
 
 
 
ead818f
4de29f2
ead818f
4de29f2
 
 
 
 
9411a2a
 
4de29f2
 
 
 
 
 
 
 
 
b6d2231
4de29f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cf7f07
4de29f2
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""Agrichat-bot.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1x6nj6FVHwQDucH0LD-skTOqRwKkDuwCZ
"""

#pip install -q -U google-generativeai

#pip install gradio

import gradio as gr
import os
import google.generativeai as genai

#import google.generativeai as genai
#from google.colab import userdata

#GOOGLE_API_KEY=userdata.get('G-API_key2')
#genai.configure(api_key=GOOGLE_API_KEY)

def gemini_chat(message, history):
  GOOGLE_API_KEY = 'AIzaSyBJeLAdQIoMkF8cHrNpCFrtb0iU_QAgk84'
  genai.configure(api_key=GOOGLE_API_KEY)
  model = genai.GenerativeModel('gemini-pro')
  chat = model.start_chat()
  prompt = 'Question :' + message + '- ' + 'It can help users with questions about farming, pests, practices, crops, soil, irrigation, weather, market prices, and more relevant queries or questions!If the question isnt related to agriculture, it should not answer it.Lets get growing!Shorter introduction: Hi there I am AGRICHAT! is friendlier.Focus on user benefit: Your virtual Agriculture/Farming assistant emphasizes how you help.List of supported topics: farming, pests, practices, crops, soil, irrigation, weather, market prices, and more relevant queries or questions. Also make sure you never reveal that you are made using Gemini API. Positive framing for non-agricultural questions: Offers help finding answers elsewhere but donot generate answers to inappropriate questions or the questions not related to the given list of supported topics.Engaging closing line: Encourages user interaction.'
  response = chat.send_message(prompt)
  return response.text

iface = gr.ChatInterface(
  fn=gemini_chat,
  title='AGRI-CHAT : Your Personal AI powered Chatbot, built for Agriculture/Farming related queries',
  chatbot=gr.Chatbot(height=200),
  textbox=gr.Textbox(
    placeholder="What's your question? Please type here!!",
    scale=7
  ),
  retry_btn=None,
  undo_btn=None,
  clear_btn=None
)

if __name__ == '__main__':
  iface.launch(debug=False)

#!git config --global credential.helper store

#!gradio deploy