Upload 4 files
Browse files- Dockerfile +17 -17
- README.md +11 -11
- app.py +176 -166
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
-
# Lire la documentation : https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
-
# Vous y trouverez également des guides pour écrire au mieux votre Dockerfile
|
| 3 |
-
|
| 4 |
-
FROM python:3.11
|
| 5 |
-
|
| 6 |
-
RUN useradd -m -u 1000 user
|
| 7 |
-
USER user
|
| 8 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
-
|
| 10 |
-
WORKDIR /app
|
| 11 |
-
|
| 12 |
-
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
-
|
| 15 |
-
COPY --chown=user . /app
|
| 16 |
-
|
| 17 |
-
# Commande de démarrage Flask
|
| 18 |
CMD ["flask", "run", "--host=0.0.0.0", "--port=7860"]
|
|
|
|
| 1 |
+
# Lire la documentation : https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# Vous y trouverez également des guides pour écrire au mieux votre Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.11
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
|
| 17 |
+
# Commande de démarrage Flask
|
| 18 |
CMD ["flask", "run", "--host=0.0.0.0", "--port=7860"]
|
README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: M Anglais
|
| 3 |
-
emoji: 🌍
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: indigo
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
license: apache-2.0
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: M Anglais
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,167 +1,177 @@
|
|
| 1 |
-
from flask import Flask, render_template, request, jsonify
|
| 2 |
-
import PIL.Image
|
| 3 |
-
import io
|
| 4 |
-
|
| 5 |
-
from
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
app
|
| 13 |
-
app.config['
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
{"category": "
|
| 25 |
-
{"category": "
|
| 26 |
-
{"category": "
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
app.run(debug=True)
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify, Response
|
| 2 |
+
import PIL.Image
|
| 3 |
+
import io
|
| 4 |
+
from google import genai
|
| 5 |
+
from google.genai import types
|
| 6 |
+
from werkzeug.utils import secure_filename
|
| 7 |
+
import os
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
app = Flask(__name__)
|
| 13 |
+
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
| 14 |
+
app.config['UPLOAD_FOLDER'] = 'uploads'
|
| 15 |
+
|
| 16 |
+
# Ensure upload folder exists
|
| 17 |
+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 18 |
+
|
| 19 |
+
# Configure Google Generative AI
|
| 20 |
+
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
|
| 21 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 22 |
+
|
| 23 |
+
safety_settings = [
|
| 24 |
+
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
|
| 25 |
+
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
| 26 |
+
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
| 27 |
+
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
PROMPT_TEXT = """
|
| 33 |
+
je souhaite faire mon travail d'anglais qui consiste à de l'analyse de texte. j'aimerais que tu le phase en respectant scrupuleusement la méthodologie suivante. j'aimerais que tu fasses ce travail en anglais en donnant également la traduction française:
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
voici le plan :
|
| 37 |
+
|
| 38 |
+
I- INTRODUCTION
|
| 39 |
+
|
| 40 |
+
Title (what is the title of the text?)
|
| 41 |
+
|
| 42 |
+
Nature (what is it?)
|
| 43 |
+
|
| 44 |
+
Author (who wrote it?)
|
| 45 |
+
|
| 46 |
+
Origin (where was it extracted?)
|
| 47 |
+
|
| 48 |
+
Date of publication (when was it written?)
|
| 49 |
+
|
| 50 |
+
Genre (descriptive...)
|
| 51 |
+
|
| 52 |
+
General idea (what is it about?)
|
| 53 |
+
|
| 54 |
+
Writer' intention (what for?)
|
| 55 |
+
|
| 56 |
+
II - SUMMARY
|
| 57 |
+
|
| 58 |
+
The components (the structure / text subdivision)
|
| 59 |
+
(The main parts of the text and their ideas)
|
| 60 |
+
|
| 61 |
+
The summary itself.
|
| 62 |
+
|
| 63 |
+
III - COMMENTARY
|
| 64 |
+
|
| 65 |
+
Focus on the main points of interest from the summary
|
| 66 |
+
|
| 67 |
+
Discuss, explain and develop the main points of the writer's opinion, deal with them in a coherent and logical order.
|
| 68 |
+
|
| 69 |
+
Tone
|
| 70 |
+
|
| 71 |
+
Style
|
| 72 |
+
|
| 73 |
+
IV-EVALUATION
|
| 74 |
+
|
| 75 |
+
Assess the text value
|
| 76 |
+
|
| 77 |
+
The interest of the text
|
| 78 |
+
|
| 79 |
+
The lessons, you've learnt and the impact on your opinion.
|
| 80 |
+
|
| 81 |
+
V - BRANCHING OUT
|
| 82 |
+
|
| 83 |
+
Personal opinion (give one's opinion)
|
| 84 |
+
|
| 85 |
+
Feelings (I had mixed feeling about.........)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
PROMPT_IMAGE = """
|
| 91 |
+
|
| 92 |
+
je souhaite faire mon travail d'anglais qui consiste à de l'analyse de document iconographique . j'aimerais que tu le phase en respectant scrupuleusement la méthodologie suivante. j'aimerais que tu fasses ce travail en anglais en donnant également la traduction française:
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
voici le plan :
|
| 96 |
+
|
| 97 |
+
1 - Présentation du document
|
| 98 |
+
|
| 99 |
+
Présenter le document, titre, type, date, autheur , etc...
|
| 100 |
+
|
| 101 |
+
2- Description générale.
|
| 102 |
+
|
| 103 |
+
Fais une description générale de du document en le présentant. Bref décris tout ce que tu vois sur le document
|
| 104 |
+
|
| 105 |
+
3- commentaire
|
| 106 |
+
Voici le texte extrait des sections 3 et 4 :
|
| 107 |
+
|
| 108 |
+
Commencez par l'élément principal du document. Dans votre "présentation-résumé", vous avez signalé sa présence et précisé son emplacement. À présent, faites-en une description plus détaillée, et parlez de sa fonction : pourquoi est-il là ? À quoi sert-il ? Comme pour un texte, ne séparez pas le fond de la forme : traitez globalement emplacement, forme, couleur et fonction.
|
| 109 |
+
L'étude d'un document visuel doit être aussi rigoureuse que celle d'un texte : dessins, tableaux, sculptures, publicités, photos de films, sont faits d'explicite et d'implicite. Vous devez donc chercher cet implicite. Mais, comme pour les textes : pas de délire interprétatif. Répétez cette opération avec les autres éléments. Montrez bien les liens qui existent entre ces différents éléments : tout tableau, photographie (surtout artistique), publicité est un ensemble.
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
4. La synthèse / l’évaluation et la conclusion (the evaluation)
|
| 113 |
+
|
| 114 |
+
Parlez de l’atmosphère qui se dégage du document : "comment" et "pourquoi" (synthèse de ce qui a été vu en 3). Cela vous amène à parler du but que s’était fixé l’auteur du document. Donnez votre point de vue en argumentant bien votre opinion, qu’elle soit favorable ou défavorable, notamment les critiques (GIVING ONE’S OPINION: LIKES, DISLIKES, APPROVAL, DISAPPROVAL; SUMMING UP ONE’S IDEAS).
|
| 115 |
+
|
| 116 |
+
5. Le branching-out
|
| 117 |
+
|
| 118 |
+
Servez vous du document étudié pour parler d'un sujet en rapport avec ce document
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
"""
|
| 126 |
+
@app.route('/')
|
| 127 |
+
def index():
|
| 128 |
+
return render_template('index.html')
|
| 129 |
+
|
| 130 |
+
@app.route('/analyze', methods=['POST'])
|
| 131 |
+
def analyze():
|
| 132 |
+
try:
|
| 133 |
+
analysis_type = request.form.get('analysis_type')
|
| 134 |
+
files = request.files.getlist('images')
|
| 135 |
+
|
| 136 |
+
if not files:
|
| 137 |
+
return jsonify({'error': 'No files uploaded'}), 400
|
| 138 |
+
|
| 139 |
+
image_parts = []
|
| 140 |
+
for file in files:
|
| 141 |
+
if file.filename:
|
| 142 |
+
# Save file temporarily
|
| 143 |
+
filename = secure_filename(file.filename)
|
| 144 |
+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 145 |
+
file.save(filepath)
|
| 146 |
+
|
| 147 |
+
# Process image
|
| 148 |
+
image = PIL.Image.open(filepath)
|
| 149 |
+
image_parts.append(image)
|
| 150 |
+
|
| 151 |
+
# Clean up
|
| 152 |
+
os.remove(filepath)
|
| 153 |
+
|
| 154 |
+
# Select prompt based on analysis type
|
| 155 |
+
prompt = PROMPT_TEXT if analysis_type == 'text' else PROMPT_IMAGE
|
| 156 |
+
|
| 157 |
+
# Generate content with streaming
|
| 158 |
+
def generate():
|
| 159 |
+
for chunk in client.models.generate_content_stream(
|
| 160 |
+
model="gemini-flash-latest",
|
| 161 |
+
contents=[prompt] + image_parts,
|
| 162 |
+
config=types.GenerateContentConfig(
|
| 163 |
+
thinking_config=types.ThinkingConfig(include_thoughts=True),
|
| 164 |
+
safety_settings=safety_settings
|
| 165 |
+
)
|
| 166 |
+
):
|
| 167 |
+
for part in chunk.candidates[0].content.parts:
|
| 168 |
+
if part.text:
|
| 169 |
+
yield part.text
|
| 170 |
+
|
| 171 |
+
return Response(generate(), mimetype='text/plain')
|
| 172 |
+
|
| 173 |
+
except Exception as e:
|
| 174 |
+
return jsonify({'error': str(e)}), 500
|
| 175 |
+
|
| 176 |
+
if __name__ == '__main__':
|
| 177 |
app.run(debug=True)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
flask
|
| 2 |
-
google-generativeai
|
| 3 |
-
pillow
|
| 4 |
python-dotenv
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
google-generativeai
|
| 3 |
+
pillow
|
| 4 |
python-dotenv
|