Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import cohere | |
def get_weather_data(): | |
lat = 27.0238 | |
lon = 74.2179 | |
key = "d07f2290a30824b709b50a94237cfcb7" | |
url = f"https://api.openweathermap.org/data/2.5/weather?units=metric&lat={lat}&lon={lon}&appid={key}" | |
response = requests.get(url) | |
result = response.json() | |
result["main"].update({"description": result["weather"][0]["description"]}) | |
return result["main"] | |
def generate_prompt(data): | |
weather_json = get_weather_data() | |
prompt = \ | |
f'''Category: {data["Category"]} | |
Crop Type: {data["Crop"]} | |
Query Type: {data["QueryType"]} | |
State: {data["StateName"].lower()} | |
District: {data["DistrictName"].lower()} | |
Max Temprature: {weather_json["temp_max"]} | |
Min Temprature: {weather_json["temp_min"]} | |
Humidity: {weather_json["humidity"]} | |
Weather Description: {weather_json["description"]} | |
Question: {data["QueryTranslated"]} | |
''' | |
return prompt | |
def get_response(prompt): | |
co = cohere.Client('EoYqxEa60C0EEeKadblGW8NE94geVCEE75lDqySe') | |
response = co.generate( | |
prompt = prompt, | |
) | |
return response.text | |
outputs = gr.outputs.Textbox() | |
iface = gr.Interface(fn=get_response, | |
inputs=[gr.Textbox(label = 'First Code snippet')], | |
outputs=[gr.Textbox(label = 'Summary of first Code snippet')], | |
description='The similarity score') | |
iface.launch() |