CesarLeblanc commited on
Commit
d563836
1 Parent(s): 47596a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  from datasets import load_dataset
 
 
4
 
5
  classifier = pipeline("text-classification", model="CesarLeblanc/test_model")
6
  dataset = load_dataset("CesarLeblanc/text_classification_dataset")
@@ -11,7 +13,18 @@ def text_classification(text):
11
  habitat_label = dataset['train'].features['label'].names[int(habitat_label.split('_')[1])]
12
  habitat_score = result[0]['score']
13
  formatted_output = f"This vegetation plot belongs to the habitat {habitat_label} with the probability {habitat_score*100:.2f}%"
14
- image_output = gr.Image(value='N13.jpg', type="filepath")
 
 
 
 
 
 
 
 
 
 
 
15
  return formatted_output, image_output
16
 
17
  examples=["sparganium erectum, calystegia sepium, persicaria amphibia", "thinopyrum junceum, cakile maritima"]
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  from datasets import load_dataset
4
+ import requests
5
+ from bs4 import BeautifulSoup
6
 
7
  classifier = pipeline("text-classification", model="CesarLeblanc/test_model")
8
  dataset = load_dataset("CesarLeblanc/text_classification_dataset")
 
13
  habitat_label = dataset['train'].features['label'].names[int(habitat_label.split('_')[1])]
14
  habitat_score = result[0]['score']
15
  formatted_output = f"This vegetation plot belongs to the habitat {habitat_label} with the probability {habitat_score*100:.2f}%"
16
+ floraveg_url = f"https://floraveg.eu/habitat/overview/{habitat_label}"
17
+ response = requests.get(url)
18
+ if response.status_code == 200:
19
+ soup = BeautifulSoup(response.text, 'html.parser')
20
+ img_tag = soup.find('img', src=lambda x: x and x.startswith("https://files.ibot.cas.cz/cevs/images/syntaxa/thumbs/"))
21
+ if img_tag:
22
+ image_url = img_tag['src']
23
+ else:
24
+ image_url = 'https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png'
25
+ else:
26
+ image_url = 'https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png'
27
+ image_output = gr.Image(value=image_url)
28
  return formatted_output, image_output
29
 
30
  examples=["sparganium erectum, calystegia sepium, persicaria amphibia", "thinopyrum junceum, cakile maritima"]