Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from langchain import PromptTemplate, LLMChain, OpenAI
|
|
4 |
import requests
|
5 |
import os
|
6 |
import streamlit as st
|
7 |
-
|
8 |
|
9 |
|
10 |
load_dotenv (find_dotenv())
|
@@ -57,6 +57,29 @@ def text2speech(message):
|
|
57 |
with open('audio.wav', 'wb') as file:
|
58 |
file.write(response.content)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
#scenario = img2text("mmd.png")
|
62 |
#story = generate_story(scenario)
|
@@ -82,13 +105,14 @@ def main():
|
|
82 |
st.image(uploaded_file, caption='Uploaded Image.',
|
83 |
use_column_width=True)
|
84 |
scenario = img2text(uploaded_file.name)
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
text2speech(story)
|
89 |
|
90 |
with st.expander("scenario"):
|
91 |
-
st.write(
|
92 |
with st.expander("story"):
|
93 |
st.write(story)
|
94 |
|
|
|
4 |
import requests
|
5 |
import os
|
6 |
import streamlit as st
|
7 |
+
import json
|
8 |
|
9 |
|
10 |
load_dotenv (find_dotenv())
|
|
|
57 |
with open('audio.wav', 'wb') as file:
|
58 |
file.write(response.content)
|
59 |
|
60 |
+
#translate
|
61 |
+
def translatefr(Text2img2text):
|
62 |
+
API_URL = "https://api-inference.huggingface.co/models/sgugger/marian-finetuned-kde4-en-to-fr"
|
63 |
+
headers = {"Authorization": f"Bearer {HUGGINGFACEHUB_API_TOKEN}"}
|
64 |
+
payloads = {
|
65 |
+
"inputs": Text2img2text
|
66 |
+
}
|
67 |
+
|
68 |
+
response = requests.post(API_URL, headers=headers, json=payloads)
|
69 |
+
responsejson = response.content
|
70 |
+
# Votre donnée JSON encodée en bytes
|
71 |
+
data_bytes = responsejson
|
72 |
+
|
73 |
+
# Décoder les bytes en string
|
74 |
+
data_str = data_bytes.decode('utf-8')
|
75 |
+
|
76 |
+
# Analyser la chaîne JSON pour obtenir un objet Python
|
77 |
+
data = json.loads(data_str)
|
78 |
+
|
79 |
+
# Extraire le texte souhaité
|
80 |
+
text = data[0]['translation_text']
|
81 |
+
print(text)
|
82 |
+
return text
|
83 |
|
84 |
#scenario = img2text("mmd.png")
|
85 |
#story = generate_story(scenario)
|
|
|
105 |
st.image(uploaded_file, caption='Uploaded Image.',
|
106 |
use_column_width=True)
|
107 |
scenario = img2text(uploaded_file.name)
|
108 |
+
scenariofr = translatefr(scenario)
|
109 |
+
story = generate_story(scenariofr)
|
110 |
+
#en_fr_translator = pipeline("translation_en_to_fr")
|
111 |
+
#story_fr = en_fr_translator(story)[0]["translation_text"]
|
112 |
text2speech(story)
|
113 |
|
114 |
with st.expander("scenario"):
|
115 |
+
st.write(scenariofr)
|
116 |
with st.expander("story"):
|
117 |
st.write(story)
|
118 |
|