Hayloo9838 commited on
Commit
2657af9
·
verified ·
1 Parent(s): 8be6adb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -24
app.py CHANGED
@@ -1,29 +1,14 @@
1
  import gradio as gr
2
- from PIL import Image
3
- import torch
4
- from transformers import ViTFeatureExtractor, ViTForImageClassification
5
 
6
- # Load model + processor
7
- model = ViTForImageClassification.from_pretrained("Falconsai/nsfw_image_detection")
8
- processor = ViTFeatureExtractor.from_pretrained("Falconsai/nsfw_image_detection")
9
 
10
- def predict(image):
11
- # Process image
12
- inputs = processor(images=image, return_tensors="pt")
13
- with torch.no_grad():
14
- outputs = model(**inputs)
15
- logits = outputs.logits
16
- predicted_class_idx = logits.argmax(-1).item()
17
- label = model.config.id2label[predicted_class_idx]
18
- return label
19
 
20
- # Gradio Interface
21
- demo = gr.Interface(
22
- fn=predict,
23
- inputs=gr.Image(type="pil", label="Upload Image"),
24
- outputs=gr.Label(label="Prediction"),
25
- title="NSFW Image Detection (ViT)",
26
- description="Upload an image to classify if it's NSFW or SFW."
27
- )
28
 
29
- demo.launch(debug=True, server_name="0.0.0.0", server_port=7860)
 
 
 
 
1
  import gradio as gr
2
+ from flask import Flask
 
 
3
 
4
+ app = Flask(__name__)
 
 
5
 
6
+ def greet(name):
7
+ return f"Hello, {name}!"
 
 
 
 
 
 
 
8
 
9
+ gradio_interface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
10
 
11
+ gr.mount_gradio_app(app, gradio_interface, path="/gradio")
12
+
13
+ if __name__ == "__main__":
14
+ app.run()