NKASG commited on
Commit
74bbeff
·
verified ·
1 Parent(s): fd27a87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -5,24 +5,17 @@ import requests
5
  import torch
6
 
7
  # Load model from Hugging Face model hub
8
- model_name = "your-username/your-model-name" # Replace with your model's name on Hugging Face
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  model = AutoModelForImageClassification.from_pretrained(model_name)
11
 
12
  # Define function for image preprocessing and prediction
13
  def process_image(image):
14
- # Load and preprocess image
15
- image = Image.open(image)
16
- inputs = tokenizer(image, return_tensors="pt", padding=True, truncation=True)
17
- # Make prediction
18
- outputs = model(**inputs)
19
- predicted_class = torch.argmax(outputs.logits, dim=1)
20
- return predicted_class.item()
21
 
22
- # Create Gradio interface
23
- inputs = gr.inputs.Image()
24
- output = gr.outputs.Label(num_top_classes=1)
25
- interface = gr.Interface(fn=process_image, inputs=inputs, outputs=output, capture_session=True)
26
 
27
- # Deploy the Gradio interface
28
- interface.launch(share=True)
 
5
  import torch
6
 
7
  # Load model from Hugging Face model hub
8
+ model_name = "best20.pt" # Replace with your model's name on Hugging Face
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  model = AutoModelForImageClassification.from_pretrained(model_name)
11
 
12
  # Define function for image preprocessing and prediction
13
  def process_image(image):
14
+ img_4d=img.reshape(-1,256,256,3)
15
+ prediction=Model.predict(img_4d)[0]
16
+ return {class_names[i]: float(prediction[i]) for i in range(3)}
 
 
 
 
17
 
18
+ image = gr.inputs.Image(shape=(256,256))
19
+ label = gr.outputs.Label(num_top_classes=3)
 
 
20
 
21
+ gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch()