jineetshah commited on
Commit
64cb2f9
·
unverified ·
1 Parent(s): ba45dcd

saving image

Browse files
Files changed (2) hide show
  1. app.py +15 -1
  2. requirements.txt +3 -1
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
 
 
 
4
 
5
  API_URL = "https://api-inference.huggingface.co/models/AliGhiasvand86/gisha_digit_recognition"
6
  headers = {"Authorization": "Bearer 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"}
@@ -10,8 +13,19 @@ def query(image_path):
10
  response = requests.post(API_URL, headers=headers, files={"file": file})
11
  return response.json()
12
 
 
 
 
 
 
 
 
13
  def classify_digit(image):
14
- result = query(image.name)
 
 
 
 
15
  df = pd.DataFrame(result)
16
  return df
17
 
 
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
4
+ from PIL import Image
5
+ import numpy as np
6
+ import base64
7
 
8
  API_URL = "https://api-inference.huggingface.co/models/AliGhiasvand86/gisha_digit_recognition"
9
  headers = {"Authorization": "Bearer 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"}
 
13
  response = requests.post(API_URL, headers=headers, files={"file": file})
14
  return response.json()
15
 
16
+ def save_array_as_image(array, image_path):
17
+ # Convert the array to an image
18
+ image = Image.fromarray(array)
19
+
20
+ # Save the image to the specified path
21
+ image.save(image_path)
22
+
23
  def classify_digit(image):
24
+ # Save the image as a .png file
25
+ image_path = "sketchpad.png"
26
+ save_array_as_image(image, image_path)
27
+
28
+ result = query(image_path)
29
  df = pd.DataFrame(result)
30
  return df
31
 
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
  gradio
2
  requests
3
- pandas
 
 
 
1
  gradio
2
  requests
3
+ pandas
4
+ numpy
5
+ pillow