Paarth commited on
Commit
da3f560
1 Parent(s): 461efc7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import cohere
4
+
5
+
6
+ def get_weather_data():
7
+ lat = 27.0238
8
+ lon = 74.2179
9
+ key = "d07f2290a30824b709b50a94237cfcb7"
10
+ url = f"https://api.openweathermap.org/data/2.5/weather?units=metric&lat={lat}&lon={lon}&appid={key}"
11
+ response = requests.get(url)
12
+ result = response.json()
13
+ result["main"].update({"description": result["weather"][0]["description"]})
14
+ return result["main"]
15
+
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()