Skip to content
Snippets Groups Projects
Commit 6a0b11fb authored by Petit Victor's avatar Petit Victor
Browse files

Merge remote-tracking branch 'origin/master'

parents f564e645 e3989126
No related branches found
No related tags found
No related merge requests found
......@@ -42,11 +42,17 @@ import sys
import tarfile
import random
import string
from textblob import TextBlob
import numpy as np
from six.moves import urllib
import tensorflow as tf
from twitter_to_images import *
import dash
import dash_core_components as dcc
import dash_html_components as html
import random
FLAGS = None
......@@ -118,24 +124,74 @@ class NodeLookup(object):
if node_id not in self.node_lookup:
return ''
return self.node_lookup[node_id]
import random
def api_final(txt):
liste_data = collect_image_url(txt)
url,txt,id = liste_data[random.randint(1,len(liste_data))]
url,txt,id = liste_data[random.randint(0,len(liste_data)-1)]
aleat_str=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
load_requests(url, aleat_str+'.jpg')
liste_pred = run_inference_on_image(aleat_str +'.jpg')
return(aleat_str + '.jpg', liste_pred,txt,id)
return(url,aleat_str + '.jpg', liste_pred,txt,id)
from vocabulary.vocabulary import Vocabulary as vb
def string_to_comment(str):
proba=0
text=""
while len(text)==0:
url,image,pred,txt_origin,id= api_final(str)
word,x=pred[0]
#word_1,proba=pred[0]
#word_2,x=pred[1]
#text=collect_text_mots(word_1,word_2)
text=select_by_positivity(word)
text.replace(":"," ")
with open ("fichier.txt","w") as fichier:
fichier.write(url+";;;" + text+ ";;;" + word)
return (image,text,id,txt_origin,word)
def create_graph():
"""Creates a graph from saved GraphDef file and returns a saver."""
# Creates graph from saved graph_def.pb.
with tf.gfile.FastGFile(os.path.join(
FLAGS.model_dir, 'classify_image_graph_def.pb'), 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
def separator(text):
interdits="\"[]\\"
sentences=[]
i=0
insent=False
while i<len(text):
if insent:
if text[i] == '}':
insent=False
elif text[i] not in interdits:
sentences[-1] += text[i]
elif text[i] == '{':
insent=True
sentences.append('')
i+=1
return [s[12:] for s in sentences]
def example_sentences(word):
return separator(vb.usage_example(word))
def select_by_positivity(word):
sents=example_sentences(word)
pos=0
s=TextBlob('')
for text in sents:
for sent in TextBlob(text).sentences:
if sent.sentiment.polarity <= -0.1:#and word in str(sent):
s=sent
pos=sent.sentiment.polarity
return(str(s))
def run_inference_on_image(image):
"""Runs inference on an image.
......@@ -179,7 +235,14 @@ def run_inference_on_image(image):
liste_pred.append((human_string,score))
return liste_pred
def create_graph():
"""Creates a graph from saved GraphDef file and returns a saver."""
# Creates graph from saved graph_def.pb.
with tf.gfile.FastGFile(os.path.join(
FLAGS.model_dir, 'classify_image_graph_def.pb'), 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
def maybe_download_and_extract():
"""Download and extract model tar file."""
......@@ -199,14 +262,12 @@ def maybe_download_and_extract():
print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
tarfile.open(filepath, 'r:gz').extractall(dest_directory)
def main(_):
maybe_download_and_extract()
image = (FLAGS.image_file if FLAGS.image_file else
os.path.join(FLAGS.model_dir, 'cropped_panda.jpg'))
run_inference_on_image(image)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# classify_image_graph_def.pb:
......@@ -242,3 +303,10 @@ if __name__ == '__main__':
dash1.py 0 → 100644
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
with open ("fichier.txt", "r") as f :
for line in f:
print (line)
url,txt,words=line.split(";;;")
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
html.H1(
children='MVP',
style={
'textAlign': 'center',
'color': colors['text']
}
),
html.H2(children='Génerer des commentaires de tweets à partir de leur image', style={
'textAlign': 'center',
'color': colors['text']
}),
html.Img(src=url,width=200,height=300),
html.Div(
children='les mots trouvés sont : ' + words,
style={
'position': 'absolute',
'width':'400px',
'top': '250px',
'left': '300px',
'textAlign': 'center',
'color': '#00FF00'
}
),
html.Div(
children=txt,
style={
'textAlign': 'center',
'color': '#FFFFFF',
'position': 'absolute',
'width':'400px',
'top': '320px',
'left': '300px',
}
),
])
if __name__ == '__main__':
app.run_server(debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment