Mr-Vicky-01 commited on
Commit
ba289e3
1 Parent(s): 973918a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -24,7 +24,7 @@ def generate_story_from_caption(caption):
24
  # Generate story based on caption
25
  api_key = os.getenv("GOOGLE_API")
26
  prompt_template = """You are a story teller;
27
- You can generate a short story based on a simple narrative, the story should between 30 to 50 words;
28
  CONTEXT: {scenario}
29
  Story: """
30
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["scenario"])
@@ -35,10 +35,15 @@ def generate_story_from_caption(caption):
35
  return story
36
 
37
  def text_to_speech(text):
38
- # Convert text to speech
39
- tts = gTTS(text=text, lang='en')
40
- tts.save("output.mp3")
41
- return "output.mp3"
 
 
 
 
 
42
 
43
  def generate_story_from_image(image_input):
44
  input_image = Image.fromarray(image_input)
 
24
  # Generate story based on caption
25
  api_key = os.getenv("GOOGLE_API")
26
  prompt_template = """You are a story teller;
27
+ You can generate a short story based on a simple narrative, the story should between 30 to 80 words;
28
  CONTEXT: {scenario}
29
  Story: """
30
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["scenario"])
 
35
  return story
36
 
37
  def text_to_speech(text):
38
+ headers = {"Authorization": f"Bearer {os.getenv('HUGGING_FACE')}"}
39
+ payload = {"inputs": text}
40
+ API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"
41
+ response = requests.post(API_URL, headers=headers, json=payload)
42
+
43
+ if response.status_code == 200:
44
+ with open("output.mp3", "wb") as f:
45
+ f.write(response.content)
46
+ return "output.mp3"
47
 
48
  def generate_story_from_image(image_input):
49
  input_image = Image.fromarray(image_input)