IshmamF commited on
Commit
2cebe33
·
verified ·
1 Parent(s): 1090b30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -1,12 +1,42 @@
1
  import os
2
  import requests
3
  from geopy.geocoders import GoogleV3
4
- from text2image import generate_image
5
  import streamlit as st
6
 
7
  API_KEY = os.getenv('WEATHER_API')
8
  GOOGLE_API = os.getenv('GOOGLE_API')
9
  geolocator = GoogleV3(api_key=GOOGLE_API)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  st.title("Weather Image")
12
 
@@ -19,7 +49,6 @@ submit = st.button("Submit", type="primary")
19
  # CITY = 'London'
20
  # url = f"https://api.openweathermap.org/data/2.5/weather?q={CITY}&appid={API_KEY}"
21
 
22
-
23
  if user_input and submit:
24
  location = geolocator.geocode(user_input)
25
  url = f"https://api.openweathermap.org/data/2.5/weather?lat={location.latitude}&lon={location.longitude}&appid={API_KEY}"
 
1
  import os
2
  import requests
3
  from geopy.geocoders import GoogleV3
 
4
  import streamlit as st
5
 
6
  API_KEY = os.getenv('WEATHER_API')
7
  GOOGLE_API = os.getenv('GOOGLE_API')
8
  geolocator = GoogleV3(api_key=GOOGLE_API)
9
+ STABLE_API = os.getenv("STABLE_API")
10
+
11
+ def generate_image(prompt):
12
+ url = "https://stablediffusionapi.com/api/v3/text2img"
13
+
14
+ payload = json.dumps({
15
+ "key": STABLE_API,
16
+ "prompt": prompt,
17
+ "negative_prompt": None,
18
+ "width": "512",
19
+ "height": "512",
20
+ "samples": "1",
21
+ "num_inference_steps": "20",
22
+ "seed": None,
23
+ "guidance_scale": 7.5,
24
+ "safety_checker": "yes",
25
+ "multi_lingual": "no",
26
+ "panorama": "no",
27
+ "self_attention": "no",
28
+ "upscale": "no",
29
+ "embeddings_model": None,
30
+ "webhook": None,
31
+ "track_id": None
32
+ })
33
+
34
+ headers = {
35
+ 'Content-Type': 'application/json'
36
+ }
37
+
38
+ response = requests.request("POST", url, headers=headers, data=payload)
39
+ return response.json()["output"][0]
40
 
41
  st.title("Weather Image")
42
 
 
49
  # CITY = 'London'
50
  # url = f"https://api.openweathermap.org/data/2.5/weather?q={CITY}&appid={API_KEY}"
51
 
 
52
  if user_input and submit:
53
  location = geolocator.geocode(user_input)
54
  url = f"https://api.openweathermap.org/data/2.5/weather?lat={location.latitude}&lon={location.longitude}&appid={API_KEY}"