BillyAggarwal commited on
Commit
fcd3028
·
verified ·
1 Parent(s): e6dad3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -1,20 +1,30 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
 
3
 
4
- client = InferenceClient("BillyAggarwal/NeuralStyleTrasnferModel.keras")
 
5
 
6
- def style_transfer(content_image, style_image):
7
- # send images to Hugging Face model
8
- result = client.post(
9
- json={"inputs": {"content": content_image, "style": style_image}}
10
- )
11
- return result
 
 
 
 
 
 
 
 
12
 
13
  demo = gr.Interface(
14
  fn=style_transfer,
15
- inputs=[gr.Image(), gr.Image()],
16
  outputs=gr.Image(),
17
- title="Neural Style Transfer"
18
  )
19
 
20
- demo.launch()
 
1
  import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
 
6
+ # Load your Keras model
7
+ model = tf.keras.models.load_model("NeuralStyleTransferModel.keras")
8
 
9
+ def style_transfer(content, style):
10
+ content = Image.fromarray(content).resize((256, 256))
11
+ style = Image.fromarray(style).resize((256, 256))
12
+
13
+ # preprocess (example: normalize, expand dims, etc.)
14
+ content_arr = np.expand_dims(np.array(content) / 255.0, axis=0)
15
+ style_arr = np.expand_dims(np.array(style) / 255.0, axis=0)
16
+
17
+ # run through your model
18
+ output = model.predict([content_arr, style_arr])
19
+
20
+ # postprocess
21
+ output_img = (output[0] * 255).astype("uint8")
22
+ return Image.fromarray(output_img)
23
 
24
  demo = gr.Interface(
25
  fn=style_transfer,
26
+ inputs=[gr.Image(type="numpy"), gr.Image(type="numpy")],
27
  outputs=gr.Image(),
 
28
  )
29
 
30
+ demo.launch()