Update app.py
Browse files
app.py
CHANGED
@@ -10,18 +10,7 @@ genai.configure(api_key=api_key)
|
|
10 |
model = genai.GenerativeModel("gemini-pro")
|
11 |
|
12 |
# Define a prompt template
|
13 |
-
prompt_template = """
|
14 |
-
You are a virtual assistant designed to provide Kerala farmers with comprehensive information about Kerala agriculture. you know both malayalam and english ,you shuould coomunicate both in malayalam and english when they demand only ,Your knowledge base includes:
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
# What are the symptoms of Yellow Stem Borer on rice fields?
|
19 |
-
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. (C.O: Scirpophaga incertulas).
|
20 |
-
# What are the symptoms of Brown Plant attack on rice fields Hopper?
|
21 |
-
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. (C.O: Nilaparvata lugens).
|
22 |
-
# What are the symptoms of Rice Bug attack on fields?
|
23 |
-
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. ETL: 5 bugs/100 panicles or 1 bug/hill - flowering stage; 16 bugs/100 panicles or 3 bug/ hill at milky stage. (C.O: Leptocorisa acuta).
|
24 |
-
"""
|
25 |
|
26 |
# Start the chat without the 'context' argument
|
27 |
chat = model.start_chat(history=[])
|
@@ -36,26 +25,36 @@ def get_gemini_response(question):
|
|
36 |
full_response += chunk.text
|
37 |
return full_response
|
38 |
|
39 |
-
|
40 |
# Interface using Gradio
|
41 |
theme = gr.themes.Soft()
|
42 |
-
|
|
|
43 |
gr.Markdown(
|
44 |
"""
|
45 |
<div style="text-align: center;">
|
46 |
-
<h1 style="color: #
|
47 |
-
<p style="color: #
|
48 |
</div>
|
49 |
"""
|
50 |
)
|
|
|
51 |
chatbot = gr.Chatbot(elem_classes="colorful-chatbot")
|
52 |
-
msg = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
variant="primary",
|
59 |
)
|
60 |
|
61 |
# Response Function (unchanged)
|
@@ -65,8 +64,12 @@ with gr.Blocks(theme=theme, css=".gradio-container {background-color: #20e80e}")
|
|
65 |
return "", chat_history
|
66 |
|
67 |
# Submit Message & Update Chat
|
68 |
-
|
|
|
|
|
|
|
69 |
|
70 |
# Launch the Chat Interface
|
71 |
if __name__ == "__main__":
|
72 |
-
demo.launch()
|
|
|
|
10 |
model = genai.GenerativeModel("gemini-pro")
|
11 |
|
12 |
# Define a prompt template
|
13 |
+
prompt_template = """You are a virtual assistant designed to provide Kerala farmers with comprehensive information about Kerala agriculture. you know both malayalam and english ,you shuould coomunicate both in malayalam and english when they demand only ,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. (C.O: Scirpophaga incertulas).# 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. (C.O: Nilaparvata lugens).# 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. ETL: 5 bugs/100 panicles or 1 bug/hill - flowering stage; 16 bugs/100 panicles or 3 bug/ hill at milky stage. (C.O: Leptocorisa acuta)."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Start the chat without the 'context' argument
|
16 |
chat = model.start_chat(history=[])
|
|
|
25 |
full_response += chunk.text
|
26 |
return full_response
|
27 |
|
|
|
28 |
# Interface using Gradio
|
29 |
theme = gr.themes.Soft()
|
30 |
+
|
31 |
+
with gr.Blocks(theme=theme, css=".gradio-container {background-color: #f0f0f0}") as demo:
|
32 |
gr.Markdown(
|
33 |
"""
|
34 |
<div style="text-align: center;">
|
35 |
+
<h1 style="font-family: 'Arial', sans-serif; color: #333;">Krishi Sahayak</h1>
|
36 |
+
<p style="font-family: 'Arial', sans-serif; color: #555;">Your Virtual Agricultural Assistant 🌱</p>
|
37 |
</div>
|
38 |
"""
|
39 |
)
|
40 |
+
|
41 |
chatbot = gr.Chatbot(elem_classes="colorful-chatbot")
|
42 |
+
msg = gr.Textbox(
|
43 |
+
label="Your Message",
|
44 |
+
placeholder="Type your message here...",
|
45 |
+
show_label=False, # Hide the label
|
46 |
+
)
|
47 |
+
|
48 |
+
# Submit Button (Styled)
|
49 |
+
submit_button = gr.Button(
|
50 |
+
"Send",
|
51 |
+
variant="primary", # Make it stand out
|
52 |
+
)
|
53 |
|
54 |
+
# Clear Button (Styled)
|
55 |
+
clear_button = gr.Button(
|
56 |
+
"Clear Conversation",
|
57 |
+
variant="secondary", # Less emphasis
|
|
|
58 |
)
|
59 |
|
60 |
# Response Function (unchanged)
|
|
|
64 |
return "", chat_history
|
65 |
|
66 |
# Submit Message & Update Chat
|
67 |
+
submit_button.click(respond, [msg, chatbot], [msg, chatbot])
|
68 |
+
|
69 |
+
# Clear Chat History
|
70 |
+
clear_button.click(lambda: None, None, chatbot, queue=False)
|
71 |
|
72 |
# Launch the Chat Interface
|
73 |
if __name__ == "__main__":
|
74 |
+
demo.launch()
|
75 |
+
|