Aabbhishekk commited on
Commit
42af165
·
1 Parent(s): ca2d4ae

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ import gradio as gr
4
+ from PIL import Image
5
+ import io
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/playgroundai/playground-v2-1024px-aesthetic"
8
+ headers = {"Authorization": "Bearer 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"}
9
+
10
+ def query(payload):
11
+ response = requests.post(API_URL, headers=headers, json=payload)
12
+ image_bytes = response.content
13
+ # image = Image.open(io.BytesIO(image_bytes))
14
+ # return image_bytes
15
+ image = Image.open(io.BytesIO(image_bytes))
16
+ return image
17
+
18
+ # user_input = "a man on the mars"
19
+ # image_bytes = query({
20
+ # "inputs": user_input,
21
+ # })
22
+
23
+
24
+ # print(image_bytes)
25
+
26
+
27
+
28
+ # demo = gr.Interface(fn=query, inputs="text", outputs="image")
29
+
30
+
31
+ # # You can access the image with PIL.Image for example
32
+ # import io
33
+ # from PIL import Image
34
+ # image = Image.open(io.BytesIO(image_bytes))
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ # import numpy as np
45
+
46
+
47
+ # def sepia(input_img):
48
+ # sepia_filter = np.array([
49
+ # [0.393, 0.769, 0.189],
50
+ # [0.349, 0.686, 0.168],
51
+ # [0.272, 0.534, 0.131]
52
+ # ])
53
+ # sepia_img = input_img.dot(sepia_filter.T)
54
+ # sepia_img /= sepia_img.max()
55
+ # return sepia_img
56
+
57
+ # demo = gr.Interface(image, gr.Image(), "image")
58
+ # demo.launch()
59
+ # demo = gr.Image(image)
60
+
61
+ # demo.launch()
62
+ with gr.Blocks() as demo:
63
+ gr.Interface(fn=query, inputs="text", outputs="image")
64
+
65
+ demo.launch()