aksara_1 / app.py
praveenpankaj's picture
Updated app to aksara v1 dashboard
c7b6715 verified
raw
history blame
3.19 kB
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