Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +21 -20
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import cohere
|
| 4 |
-
|
| 5 |
|
| 6 |
def get_weather_data():
|
| 7 |
lat = 27.0238
|
|
@@ -16,34 +16,35 @@ def get_weather_data():
|
|
| 16 |
def generate_prompt(data):
|
| 17 |
weather_json = get_weather_data()
|
| 18 |
prompt = \
|
| 19 |
-
f'''
|
| 20 |
-
Crop Type: {data["Crop"]}
|
| 21 |
-
Query Type: {data["QueryType"]}
|
| 22 |
-
State: {data["StateName"].lower()}
|
| 23 |
-
District: {data["DistrictName"].lower()}
|
| 24 |
Max Temprature: {weather_json["temp_max"]}
|
| 25 |
Min Temprature: {weather_json["temp_min"]}
|
| 26 |
Humidity: {weather_json["humidity"]}
|
| 27 |
Weather Description: {weather_json["description"]}
|
| 28 |
-
|
|
|
|
| 29 |
'''
|
| 30 |
return prompt
|
| 31 |
|
| 32 |
def get_response(prompt):
|
| 33 |
co = cohere.Client('EoYqxEa60C0EEeKadblGW8NE94geVCEE75lDqySe')
|
| 34 |
-
|
|
|
|
| 35 |
model='command-xlarge-nightly',
|
| 36 |
-
prompt =
|
| 37 |
-
max_tokens=
|
| 38 |
-
temperature=0.6,
|
| 39 |
-
stop_sequences=["--"]
|
| 40 |
)
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import cohere
|
| 4 |
+
from translate import Translator
|
| 5 |
|
| 6 |
def get_weather_data():
|
| 7 |
lat = 27.0238
|
|
|
|
| 16 |
def generate_prompt(data):
|
| 17 |
weather_json = get_weather_data()
|
| 18 |
prompt = \
|
| 19 |
+
f'''State: Rajasthan
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
Max Temprature: {weather_json["temp_max"]}
|
| 21 |
Min Temprature: {weather_json["temp_min"]}
|
| 22 |
Humidity: {weather_json["humidity"]}
|
| 23 |
Weather Description: {weather_json["description"]}
|
| 24 |
+
Context: Through increased use of soil testing and plant analyses, micronutrient deficiencies have been verified in many soils. Some reasons limiting the incidental additions of micronutrients include.High-yield crop demands remove micronutrients from the soil. Increased use of high-analysis NPK fertilizers containing lower quantities of micronutrient contaminants. Advances in fertilizer technology reduce the residual addition of micronutrients.
|
| 25 |
+
Question: {data}
|
| 26 |
'''
|
| 27 |
return prompt
|
| 28 |
|
| 29 |
def get_response(prompt):
|
| 30 |
co = cohere.Client('EoYqxEa60C0EEeKadblGW8NE94geVCEE75lDqySe')
|
| 31 |
+
new_prompt = generate_prompt(prompt)
|
| 32 |
+
response = co.generate(
|
| 33 |
model='command-xlarge-nightly',
|
| 34 |
+
prompt = new_prompt,
|
| 35 |
+
max_tokens = 1000,
|
| 36 |
+
temperature = 0.6,
|
| 37 |
+
stop_sequences = ["--"]
|
| 38 |
)
|
| 39 |
+
translator = Translator(to_lang="hi")
|
| 40 |
+
translation = translator.translate(response.generations[0].text)
|
| 41 |
+
return translation
|
| 42 |
|
| 43 |
+
title = """<h1 align="center">🌱 Farmer Queries LLM | किसान प्रश्न LLM 🌾</h1>"""
|
| 44 |
+
with gr.Blocks(css="""#col_container {margin-left: auto; margin-right: auto;} #chatbot {height: 520px; overflow: auto;}""") as demo:
|
| 45 |
+
gr.HTML(title)
|
| 46 |
+
input1 = gr.Textbox(label = 'प्रश्न पूछो')
|
| 47 |
+
output1 = gr.Textbox(label = 'उत्तर')
|
| 48 |
+
btn = gr.Button("जमा करे")
|
| 49 |
+
btn.click(get_response, [input1], output1)
|
| 50 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
cohere
|
|
|
|
|
|
| 1 |
+
cohere
|
| 2 |
+
translate
|