Paarth commited on
Commit
bc26d0d
1 Parent(s): da3f560

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +21 -20
  2. 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'''Category: {data["Category"]}
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
- Question: {data["QueryTranslated"]}
 
29
  '''
30
  return prompt
31
 
32
  def get_response(prompt):
33
  co = cohere.Client('EoYqxEa60C0EEeKadblGW8NE94geVCEE75lDqySe')
34
- response = co.generate(
 
35
  model='command-xlarge-nightly',
36
- prompt = prompt,
37
- max_tokens=40,
38
- temperature=0.6,
39
- stop_sequences=["--"]
40
  )
41
- print(response[0])
42
- return response.generations[0].text
 
43
 
44
- outputs = gr.outputs.Textbox()
45
- iface = gr.Interface(fn=get_response,
46
- inputs=[gr.Textbox(label = 'First Code snippet')],
47
- outputs=[gr.Textbox(label = 'Summary of first Code snippet')],
48
- description='The similarity score')
49
- iface.launch()
 
 
 
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