File size: 3,186 Bytes
0d4fb3b
c7b6715
 
0d4fb3b
c7b6715
 
 
 
 
 
 
 
 
 
0d4fb3b
c7b6715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import gradio as gr
import sqlite3
import pandas as pd
import time
import huggingface_hub
import shutil
import os
import datetime
from apscheduler.schedulers.background import BackgroundScheduler

from rag_output import rag_response


TOKEN = os.environ.get('HFW_TOKEN')
    
def llm_response(message, history):
    
    res = rag_response(message)
    
    for i in range(len(res)):
        time.sleep(0.02)
        yield res[: i+1]
    # return res


def vote(response: gr.LikeData):
    if response.liked:
        add_review(1, response.value)
    else:
        add_review(0, response.value)
        

examples = ["What are the recommended NPK dosage for maize varieties?", 
            # "What are the recommended chemical treatments to control army worms in wheat crops?", 
            "Heavy rains are predicted next week. Is my rice crop ready for this, or should I harvest early?", 
            "What crops can I grow during the dry season to use water more efficiently?", 
            "How can I improve the health of my soil after a wheat harvest, using natural methods?", 
            # "Are there crop rotation techniques that can reduce fertilizer needs for barley?"
           ]

# js_func = """
# function refresh() {
#     const url = new URL(window.location);

#     if (url.searchParams.get('__theme') !== 'light') {
#         url.searchParams.set('__theme', 'light');
#         window.location.href = url.href;
#     }
# }
# """



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."

title = "akṣara"
theme = gr.themes.Soft(primary_hue="sky",)



chatbot = gr.Chatbot(height="450px", 
                     show_copy_button=True, 
                     show_label=False,
                     avatar_images=("user.webp","cropin.png"))

textbox = gr.Textbox(placeholder="Ask akṣara...",
                    min_width=300)
with gr.Blocks(theme=theme, title=title, css="footer {visibility: hidden}") as akshara:

    gr.HTML("""<h1 style='font-family: sans-serif; text-align: center; font-size: 34px'>
        <i style='color: #04A5D9' >akṣara</i> </h1>""")

    gr.HTML("""<h3 style='font-family: sans-serif; text-align: left'>
        Welcome! </h3>""")

    # with gr.Column():

    chatbot.like(vote, None, None)

    gr.ChatInterface(fn=llm_response, 
                     examples=examples, 
                     cache_examples=False, 
                     chatbot=chatbot,
                     description=description, 
                     retry_btn="Retry", 
                     undo_btn="Undo", 
                     clear_btn="Clear",
                     submit_btn="Ask",
                     textbox=textbox
                    )

    gr.HTML("""<h3 style='font-family: sans-serif; text-align: left'>
        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
 """)



def display_ui():
    akshara.launch()


if __name__ == "__main__":
    display_ui()
    pass