|
import streamlit as st |
|
from gradio_client import Client |
|
from st_audiorec import st_audiorec |
|
|
|
|
|
|
|
TITLE = "AgriTure" |
|
DESCRIPTION = """ |
|
------------------- |
|
This Project demonstrates a model fine-tuned by Achyuth. This Model is named as "AgriTure". This Model helps the farmers and scientists to develop the art of agriculture and farming. This model helps you know about the latest advanced Farming Tips and Tricks. And helps you clarify your doubts regarding Agriculture. |
|
Hope this will be a Successful Project!!! |
|
~Achyuth |
|
------------------- |
|
""" |
|
|
|
|
|
|
|
|
|
with st.sidebar: |
|
system_promptSide = st.text_input("Optional system prompt:") |
|
temperatureSide = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05) |
|
max_new_tokensSide = st.slider("Max new tokens", min_value=0.0, max_value=4096.0, value=4096.0, step=64.0) |
|
ToppSide = st.slider("Top-p (nucleus sampling)", min_value=0.0, max_value=1.0, value=0.6, step=0.05) |
|
RepetitionpenaltySide = st.slider("Repetition penalty", min_value=0.0, max_value=2.0, value=1.2, step=0.05) |
|
|
|
whisper_client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/") |
|
|
|
|
|
def transcribe(wav_path): |
|
|
|
return whisper_client.predict( |
|
wav_path, |
|
"transcribe", |
|
api_name="/predict" |
|
) |
|
|
|
|
|
def predict(message, system_prompt='Your name is OpenGPT. You are developed by Achyuth. You need to mostly focus on giving information about future agriculture and advanced farming. Empower yourself farming future with cutting-edge technology and sustainable practices. You need to say about the latest advancements in agriculture, precision farming, and eco-friendly cultivation methods. You need to cultivate a greener and more productive. Your developer is studying in The Hyderabad Public School Kadapa.', temperature=0.7, max_new_tokens=4096,Topp=0.5,Repetitionpenalty=1.2): |
|
with st.status("Starting client"): |
|
client = Client("https://huggingface-projects-llama-2-7b-chat.hf.space/") |
|
st.write("Requesting Audio Transcriber") |
|
with st.status("Requesting AgriTure v1"): |
|
st.write("Requesting API") |
|
response = client.predict( |
|
message, |
|
system_prompt, |
|
max_new_tokens, |
|
temperature, |
|
Topp, |
|
500, |
|
Repetitionpenalty, |
|
api_name="/chat" |
|
) |
|
st.write("Done") |
|
return response |
|
|
|
|
|
st.title(TITLE) |
|
st.write(DESCRIPTION) |
|
|
|
|
|
|
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"], avatar=("π§βπ»" if message["role"] == 'human' else 'π¦')): |
|
st.markdown(message["content"]) |
|
|
|
textinput = st.chat_input("Ask LLama-2-7b anything...") |
|
wav_audio_data = st_audiorec() |
|
|
|
if wav_audio_data != None: |
|
with st.status("Transcribing audio"): |
|
|
|
with open("audio.wav", "wb") as f: |
|
f.write(wav_audio_data) |
|
prompt = transcribe("audio.wav") |
|
|
|
st.write("Transcribed Given Audio") |
|
|
|
st.chat_message("human",avatar = "π§βπ»").markdown(prompt) |
|
st.session_state.messages.append({"role": "human", "content": prompt}) |
|
|
|
|
|
response = predict(message= prompt) |
|
|
|
with st.chat_message("assistant", avatar='π¦'): |
|
st.markdown(response) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
|
|
|
|
if prompt := textinput: |
|
|
|
st.chat_message("human",avatar = "π¬: ").markdown(prompt) |
|
|
|
st.session_state.messages.append({"role": "human", "content": prompt}) |
|
|
|
response = predict(message=prompt) |
|
|
|
with st.chat_message("assistant", avatar='π¦'): |
|
st.markdown(response) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
|
|
|
|
|
|
|
|
|