Spaces:
Runtime error
Runtime error
Updated app to aksara v1 dashboard
Browse files
app.py
CHANGED
@@ -1,66 +1,106 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
-
import
|
|
|
4 |
import time
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
)
|
16 |
-
|
17 |
-
history = []
|
18 |
-
|
19 |
-
def generate_text(message, history):
|
20 |
-
temp = ""
|
21 |
-
input_prompt = "Ask akṣara anything on Agriculture in the Global South.\n"
|
22 |
-
for interaction in history:
|
23 |
-
input_prompt += "[|Umano|] " + interaction[0] + "\n"
|
24 |
-
input_prompt += "[|Assistente|]" + interaction[1]
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import sqlite3
|
3 |
+
import pandas as pd
|
4 |
import time
|
5 |
+
import huggingface_hub
|
6 |
+
import shutil
|
7 |
+
import os
|
8 |
+
import datetime
|
9 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
10 |
+
|
11 |
+
from rag_output import rag_response
|
12 |
+
|
13 |
+
|
14 |
+
TOKEN = os.environ.get('HFW_TOKEN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
def llm_response(message, history):
|
17 |
+
|
18 |
+
res = rag_response(message)
|
19 |
+
|
20 |
+
for i in range(len(res)):
|
21 |
+
time.sleep(0.02)
|
22 |
+
yield res[: i+1]
|
23 |
+
# return res
|
24 |
+
|
25 |
+
|
26 |
+
def vote(response: gr.LikeData):
|
27 |
+
if response.liked:
|
28 |
+
add_review(1, response.value)
|
29 |
+
else:
|
30 |
+
add_review(0, response.value)
|
31 |
+
|
32 |
+
|
33 |
+
examples = ["What are the recommended NPK dosage for maize varieties?",
|
34 |
+
# "What are the recommended chemical treatments to control army worms in wheat crops?",
|
35 |
+
"Heavy rains are predicted next week. Is my rice crop ready for this, or should I harvest early?",
|
36 |
+
"What crops can I grow during the dry season to use water more efficiently?",
|
37 |
+
"How can I improve the health of my soil after a wheat harvest, using natural methods?",
|
38 |
+
# "Are there crop rotation techniques that can reduce fertilizer needs for barley?"
|
39 |
+
]
|
40 |
+
|
41 |
+
# js_func = """
|
42 |
+
# function refresh() {
|
43 |
+
# const url = new URL(window.location);
|
44 |
+
|
45 |
+
# if (url.searchParams.get('__theme') !== 'light') {
|
46 |
+
# url.searchParams.set('__theme', 'light');
|
47 |
+
# window.location.href = url.href;
|
48 |
+
# }
|
49 |
+
# }
|
50 |
+
# """
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
description = "Hi! I am akṣara, an AI agronomist and I am here to help you with agriculture advisories for crops like paddy, wheat, maize, Sorghum, Barley, Cotton, Sugarcane, Soybean and Millets for the Indian subcontinent."
|
55 |
+
|
56 |
+
title = "akṣara"
|
57 |
+
theme = gr.themes.Soft(primary_hue="sky",)
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
chatbot = gr.Chatbot(height="450px",
|
62 |
+
show_copy_button=True,
|
63 |
+
show_label=False,
|
64 |
+
avatar_images=("user.webp","cropin.png"))
|
65 |
+
|
66 |
+
textbox = gr.Textbox(placeholder="Ask akṣara...",
|
67 |
+
min_width=300)
|
68 |
+
with gr.Blocks(theme=theme, title=title, css="footer {visibility: hidden}") as akshara:
|
69 |
+
|
70 |
+
gr.HTML("""<h1 style='font-family: sans-serif; text-align: center; font-size: 34px'>
|
71 |
+
<i style='color: #04A5D9' >akṣara</i> </h1>""")
|
72 |
+
|
73 |
+
gr.HTML("""<h3 style='font-family: sans-serif; text-align: left'>
|
74 |
+
Welcome! </h3>""")
|
75 |
+
|
76 |
+
# with gr.Column():
|
77 |
+
|
78 |
+
chatbot.like(vote, None, None)
|
79 |
+
|
80 |
+
gr.ChatInterface(fn=llm_response,
|
81 |
+
examples=examples,
|
82 |
+
cache_examples=False,
|
83 |
+
chatbot=chatbot,
|
84 |
+
description=description,
|
85 |
+
retry_btn="Retry",
|
86 |
+
undo_btn="Undo",
|
87 |
+
clear_btn="Clear",
|
88 |
+
submit_btn="Ask",
|
89 |
+
textbox=textbox
|
90 |
+
)
|
91 |
+
|
92 |
+
gr.HTML("""<h3 style='font-family: sans-serif; text-align: left'>
|
93 |
+
Disclaimer: Beta Test version #1.0 - akṣara is still in the beta testing stage and please verify information with agronomy experts or local extensions officers
|
94 |
+
""")
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
def display_ui():
|
99 |
+
akshara.launch()
|
100 |
+
|
101 |
+
|
102 |
+
if __name__ == "__main__":
|
103 |
+
display_ui()
|
104 |
+
pass
|
105 |
+
|
106 |
+
|