Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import io
|
|
| 5 |
from PIL import Image
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
from pydub import AudioSegment
|
|
|
|
| 8 |
import json
|
| 9 |
|
| 10 |
# Charger les variables d'environnement
|
|
@@ -17,16 +18,18 @@ GEMINI_APIKEY = os.getenv('GEMINI_APIKEY')
|
|
| 17 |
# Modèle Whisper pour la transcription audio
|
| 18 |
WHISPER_APIKEY = os.getenv('WHISPER_APIKEY')
|
| 19 |
|
| 20 |
-
def TranscribeAudio(
|
|
|
|
| 21 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
| 22 |
headers = {"Authorization": f"Bearer {WHISPER_APIKEY}"}
|
| 23 |
|
| 24 |
-
def query(
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
return response.json()
|
| 27 |
|
| 28 |
-
output = query(
|
| 29 |
-
return output.get('text', 'Error transcribing audio')
|
| 30 |
|
| 31 |
def GenerateTextLLM(inputText):
|
| 32 |
url = f'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={GEMINI_APIKEY}'
|
|
@@ -34,7 +37,8 @@ def GenerateTextLLM(inputText):
|
|
| 34 |
'Content-Type': 'application/json'
|
| 35 |
}
|
| 36 |
data = {
|
| 37 |
-
"prompt": inputText
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
try:
|
|
@@ -67,7 +71,7 @@ def Main(text_input, audio_input):
|
|
| 67 |
elif audio_input:
|
| 68 |
input_data = TranscribeAudio(audio_input)
|
| 69 |
else:
|
| 70 |
-
return "Veuillez fournir un texte ou un fichier audio", None
|
| 71 |
|
| 72 |
# Générer le résumé du LLM en plusieurs axes
|
| 73 |
summarized_text = GenerateTextLLM(input_data)
|
|
@@ -81,13 +85,13 @@ def Main(text_input, audio_input):
|
|
| 81 |
# Interface Gradio
|
| 82 |
inputs = [
|
| 83 |
gr.Textbox(label="Texte (laisser vide si audio fourni)", lines=5, placeholder="Entrez votre texte ici..."),
|
| 84 |
-
gr.Audio(type="
|
| 85 |
]
|
| 86 |
|
| 87 |
outputs = [
|
| 88 |
gr.Gallery(label="Diapositives générées"),
|
| 89 |
gr.Textbox(label="Résumé en axes"),
|
| 90 |
-
|
| 91 |
]
|
| 92 |
|
| 93 |
interface = gr.Interface(
|
|
@@ -99,4 +103,4 @@ interface = gr.Interface(
|
|
| 99 |
)
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
| 102 |
-
interface.launch()
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
from pydub import AudioSegment
|
| 8 |
+
from huggingface_hub import InferenceClient
|
| 9 |
import json
|
| 10 |
|
| 11 |
# Charger les variables d'environnement
|
|
|
|
| 18 |
# Modèle Whisper pour la transcription audio
|
| 19 |
WHISPER_APIKEY = os.getenv('WHISPER_APIKEY')
|
| 20 |
|
| 21 |
+
def TranscribeAudio(inputAudio):
|
| 22 |
+
|
| 23 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
| 24 |
headers = {"Authorization": f"Bearer {WHISPER_APIKEY}"}
|
| 25 |
|
| 26 |
+
def query(filename):
|
| 27 |
+
with open(filename, "rb") as f:
|
| 28 |
+
data = f.read()
|
| 29 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
| 30 |
return response.json()
|
| 31 |
|
| 32 |
+
output = query(inputAudio)
|
|
|
|
| 33 |
|
| 34 |
def GenerateTextLLM(inputText):
|
| 35 |
url = f'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={GEMINI_APIKEY}'
|
|
|
|
| 37 |
'Content-Type': 'application/json'
|
| 38 |
}
|
| 39 |
data = {
|
| 40 |
+
"prompt": inputText,
|
| 41 |
+
"model": "gemini-1.5-flash-latest"
|
| 42 |
}
|
| 43 |
|
| 44 |
try:
|
|
|
|
| 71 |
elif audio_input:
|
| 72 |
input_data = TranscribeAudio(audio_input)
|
| 73 |
else:
|
| 74 |
+
return "Veuillez fournir un texte ou un fichier audio", None
|
| 75 |
|
| 76 |
# Générer le résumé du LLM en plusieurs axes
|
| 77 |
summarized_text = GenerateTextLLM(input_data)
|
|
|
|
| 85 |
# Interface Gradio
|
| 86 |
inputs = [
|
| 87 |
gr.Textbox(label="Texte (laisser vide si audio fourni)", lines=5, placeholder="Entrez votre texte ici..."),
|
| 88 |
+
gr.Audio(sources="upload", type="filepath", label="Fichier audio (laisser vide si texte fourni)")
|
| 89 |
]
|
| 90 |
|
| 91 |
outputs = [
|
| 92 |
gr.Gallery(label="Diapositives générées"),
|
| 93 |
gr.Textbox(label="Résumé en axes"),
|
| 94 |
+
"text"
|
| 95 |
]
|
| 96 |
|
| 97 |
interface = gr.Interface(
|
|
|
|
| 103 |
)
|
| 104 |
|
| 105 |
if __name__ == "__main__":
|
| 106 |
+
interface.launch()
|