khurrameycon commited on
Commit
908288f
·
verified ·
1 Parent(s): c870bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -6,6 +6,34 @@ import os
6
  import numpy as np
7
  import torch
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  app = FastAPI()
10
 
11
  # Initialize pipeline once at startup
@@ -13,9 +41,12 @@ pipeline = KPipeline(lang_code='a')
13
 
14
  @app.post("/generate")
15
  async def generate_audio(text: str, voice: str = "af_heart", speed: float = 1.0):
 
 
 
16
  # Generate audio
17
  generator = pipeline(
18
- text,
19
  voice=voice,
20
  speed=speed,
21
  split_pattern=r'\n+'
 
6
  import numpy as np
7
  import torch
8
 
9
+ def llm_chat_response(text):
10
+ HF_TOKEN = os.getenv("HF_TOKEN")
11
+ client = InferenceClient(api_key=HF_TOKEN)
12
+ messages = [
13
+ {
14
+ "role": "user",
15
+ "content": [
16
+ {
17
+ "type": "text",
18
+ "text": text + str('describe in one line only')
19
+ } #,
20
+ # {
21
+ # "type": "image_url",
22
+ # "image_url": {
23
+ # "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
24
+ # }
25
+ # }
26
+ ]
27
+ }
28
+ ]
29
+
30
+ response_from_llama = client.chat.completions.create(
31
+ model="meta-llama/Llama-3.2-11B-Vision-Instruct",
32
+ messages=messages,
33
+ max_tokens=500)
34
+
35
+ return response_from_llama.choices[0].message['content']
36
+
37
  app = FastAPI()
38
 
39
  # Initialize pipeline once at startup
 
41
 
42
  @app.post("/generate")
43
  async def generate_audio(text: str, voice: str = "af_heart", speed: float = 1.0):
44
+
45
+ text_reply = llm_chat_response(text)
46
+
47
  # Generate audio
48
  generator = pipeline(
49
+ text_reply,
50
  voice=voice,
51
  speed=speed,
52
  split_pattern=r'\n+'