|
import google.generativeai as genai |
|
import gradio as gr |
|
import os |
|
|
|
|
|
api_key = os.getenv("GOOGLE_API_KEY") |
|
genai.configure(api_key=api_key) |
|
|
|
|
|
model = genai.GenerativeModel("gemini-pro") |
|
|
|
|
|
prompt_template = """You are a virtual assistant designed to provide Kerala farmers with comprehensive information about Kerala agriculture. |
|
you know both malayalam and english ,only when then demand you shuould coomunicate both in malayalam otherwise use english , |
|
Your knowledge base includes: |
|
# What are the symptoms of Yellow Stem Borer on rice fields? |
|
The insect may start attacking the plants from the nursery stage. The incidence is high from October to January and February. |
|
The caterpillar enters the stem and feeds on the growing shoot. As a result the central shoot dries up and produces the characteristic dead heart. |
|
The dead tillers can be easily pulled from the base. When they attack at the time of flowering, the earheads become chaffy and and white in colour. |
|
Eggs seen in masses of 15- 80 covered with buff-coloured hairs on the upper leaf surface. Larva pale yellow with dark brown head. |
|
# What are the symptoms of Brown Plant attack on rice fields Hopper? |
|
Nymphs and adults congregate at the base of the plant above the water level and suck the sap from the |
|
tillers. The affected plant dries up and gives a scorched appearance called “hopper burn”. |
|
Circular patches of drying and lodging of matured plants are typical symptoms caused by this pest. |
|
It is the vector of grassy stunt, ragged stunt and wilted stunt diseases. |
|
White to brown nymphs and brown or white adults feeding near the base of tillers can be seen. |
|
|
|
# What are the symptoms of Rice Bug attack on fields? |
|
The attack of rice bug is seen in the milky stage. They suck the sap from grains. The attacked grains show brownish discoloured patches on the husk. |
|
Some grains or ear heads appear chaffy. The panicles will be seen standing erect because of low weight. Bugs can be seen flying about when disturbed. |
|
The bug also emits a particular buggy odour. Brownish green adults are slender with long legs and antennae. """ |
|
|
|
|
|
chat = model.start_chat(history=[]) |
|
|
|
|
|
chat.send_message(prompt_template) |
|
|
|
def get_gemini_response(question): |
|
response = chat.send_message(question, stream=True) |
|
full_response = "" |
|
for chunk in response: |
|
full_response += chunk.text |
|
return full_response |
|
|
|
|
|
theme = gr.themes.Soft() |
|
|
|
with gr.Blocks(theme=theme, css=".gradio-container {background-color: #43fa4a}") as demo: |
|
gr.Markdown( |
|
""" |
|
<div style="text-align: center;"> |
|
<h1 style="font-family: 'Arial', sans-serif; color: #333;">Farm Extension GPT</h1> |
|
<p style="font-family: 'Arial', sans-serif; color: #555;">Your Virtual Agricultural Assistant 🌱</p> |
|
</div> |
|
""" |
|
) |
|
|
|
chatbot = gr.Chatbot(elem_classes="colorful-chatbot") |
|
msg = gr.Textbox( |
|
label="Your Message", |
|
placeholder="Type your message here...", |
|
show_label=False, |
|
) |
|
|
|
|
|
submit_button = gr.Button( |
|
"Send", |
|
variant="primary", |
|
) |
|
|
|
|
|
clear_button = gr.Button( |
|
"Clear Conversation", |
|
variant="secondary", |
|
) |
|
|
|
|
|
def respond(message, chat_history): |
|
bot_message = get_gemini_response(message) |
|
chat_history.append((message, bot_message)) |
|
return "", chat_history |
|
|
|
|
|
submit_button.click(respond, [msg, chatbot], [msg, chatbot]) |
|
|
|
|
|
clear_button.click(lambda: None, None, chatbot, queue=False) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|
|
|