sufyn commited on
Commit
06ed5c6
β€’
1 Parent(s): c77be8c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+ def image(prompt):
5
+ import requests
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
8
+ key = st.secrets['auth_token']
9
+ headers = {"Authorization": key }
10
+
11
+ def query(payload):
12
+ response = requests.post(API_URL, headers=headers, json=payload)
13
+ return response.content
14
+ image_bytes = query({
15
+ "inputs": prompt,
16
+ })
17
+ # You can access the image with PIL.Image for example
18
+ import io
19
+ from PIL import Image
20
+ image = Image.open(io.BytesIO(image_bytes))
21
+ return image
22
+
23
+
24
+ def accuracy(prompt):
25
+ import requests
26
+
27
+ API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
28
+ key = st.secrets['auth_token']
29
+ headers = {"Authorization": key}
30
+
31
+ def query(payload):
32
+ response = requests.post(API_URL, headers=headers, json=payload)
33
+ return response.json()
34
+
35
+ output = query({
36
+ "inputs": {
37
+ "source_sentence": "Astronaut riding a horse",
38
+ "sentences": [
39
+ prompt
40
+ ]
41
+ },
42
+ })
43
+ return output
44
+
45
+
46
+
47
+
48
+ # Set page title
49
+ st.set_page_config(page_title="IEEE CS PROMPATHON", page_icon="πŸ“œ", layout="wide")
50
+
51
+ # Set title
52
+ st.title("IEEE CS PROMPATHON", anchor=False)
53
+ st.header("Compare Your Prompts with AI (OpenDalleV1.1 and all-MiniLM-L6-v2)", anchor=False)
54
+ st.write('by sufyaan')
55
+
56
+ # Input URL
57
+ st.divider()
58
+ prompt = st.text_input("Enter Your Prompt:", value="")
59
+
60
+ if prompt:
61
+ with st.status("Processing...", state="running", expanded=True) as status:
62
+ st.write("Generating Image ...")
63
+ img = image(prompt)
64
+ # Download image
65
+ st.divider()
66
+ st.image(img,width=800,caption=prompt)
67
+ st.write("Checking Your Accuracy...")
68
+ accuracy = accuracy(prompt)
69
+ status.update(label="Finished", state="complete")
70
+ # Show Summary
71
+ st.subheader("Accuracy:", anchor=False)
72
+ st.write(accuracy)
73
+
74
+
75
+ st.divider()
76
+ st.header("Image to be generated", anchor=False)
77
+ st.image('astro.jpg',width=600)
78
+
79
+ st.divider()
80
+ st.header("Demo with Prompts", anchor=False)
81
+ st.image('cat.png',
82
+ width=500,
83
+ caption='Prompt: black fluffy gorgeous dangerous cat animal creature, large orange eyes, big fluffy ears, piercing gaze, full moon, dark ambiance, best quality, extremely detailed')
84
+
85
+ st.divider()
86
+ st.image('korean.png',
87
+ width=500,
88
+ caption='Prompt: cinematic film still of Kodak Motion Picture Film: (Sharp Detailed Image) An Oscar winning movie for Best Cinematography a woman in a kimono standing on a subway train in Japan Kodak Motion Picture Film Style, shallow depth of field, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy')