Spaces:
Build error
Build error
Upload app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import gradio as grimport requestsimport 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( model='command-xlarge-nightly', prompt = prompt, max_tokens=40, temperature=0.6, stop_sequences=["--"] ) print(response[0]) return response.generations[0].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()app.pyAdded+49