rajistics commited on
Commit
e3ebbf6
Β·
1 Parent(s): 41901b8

first push

Browse files
Files changed (3) hide show
  1. README.md +5 -5
  2. app.py +38 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
  title: Indian Food Translator
3
- emoji: πŸ“Š
4
- colorFrom: red
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.0.26
8
  app_file: app.py
9
  pinned: false
10
- license: artistic-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Indian Food Translator
3
+ emoji:
4
+ colorFrom: orange
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.0.22
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from PIL import Image
4
+
5
+ ##Image Classification
6
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
7
+ extractor = AutoFeatureExtractor.from_pretrained("rajistics/finetuned-indian-food")
8
+ model = AutoModelForImageClassification.from_pretrained("rajistics/finetuned-indian-food")
9
+
10
+ def image_to_text(imagepic):
11
+ inputs = extractor(images=imagepic, return_tensors="pt")
12
+ outputs = model(**inputs)
13
+ logits = outputs.logits
14
+ predicted_class_idx = logits.argmax(-1).item()
15
+ return (model.config.id2label[predicted_class_idx])
16
+
17
+ ##Translation
18
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
19
+ #Get list of language codes: https://github.com/facebookresearch/flores/tree/main/flores200#languages-in-flores-200
20
+ modelt = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
21
+ tokenizert = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
22
+
23
+ def translation(text):
24
+ translator = pipeline('translation', model=modelt, tokenizer=tokenizert, src_lang="eng_Latn", tgt_lang='ron_Latn')
25
+ output = translator(text)
26
+ return (output[0]['translation_text'])
27
+
28
+ ##Translation
29
+ demo = gr.Blocks()
30
+ with demo:
31
+ image_file = gr.inputs.Image(type="pil")
32
+ b1 = gr.Button("Recognize Image")
33
+ text = gr.Textbox()
34
+ b1.click(image_to_text, inputs=image_file, outputs=text)
35
+ b2 = gr.Button("Translation")
36
+ out1 = gr.Textbox()
37
+ b2.click(translation, inputs=text, outputs=out1)
38
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #python-dotenv
2
+ #protobuf~=3.19.0
3
+ git+https://github.com/huggingface/transformers.git@33028f4c795e76f9e97226fc591bc7d0b8c7d815
4
+ gradio
5
+ Pillow