File size: 3,738 Bytes
6183a73
 
 
 
 
 
f11d2c1
6183a73
 
07b5805
 
 
 
6183a73
 
 
 
fbf2802
 
 
 
 
6183a73
 
 
 
 
 
 
fbf2802
 
 
 
6183a73
 
 
 
fbf2802
cb7e557
6183a73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbf2802
5278117
 
 
6183a73
fbf2802
 
 
 
 
 
 
9e55dd9
867e2ef
5278117
867e2ef
5278117
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
import streamlit as st
import os
import requests
import io
from PIL import Image
from IPython.display import Audio, display
from freeGPT import Client as gptClient
from gradio_client import Client

#api_token = os.environ.get("API_TOKEN")
#API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-small"
#API_URL_IMG = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
#headers = {"Authorization": f"Bearer {api_token}"}

def get_speech(text, voice):
    client = Client("https://collabora-whisperspeech.hf.space/")
    result = client.predict(
      text, # str  in 'Enter multilingual text💬📝' Textbox component
      voice, # filepath  in 'Upload or Record Speaker Audio (optional)🌬️💬' Audio component
      "", # str  in 'alternatively, you can paste in an audio file URL:' Textbox component
      14, # float (numeric value between 10 and 15) in 'Tempo (in characters per second)' Slider component
      api_name="/whisper_speech_demo"
    )
    print(result)
    return result
    
def get_dreamtalk(image_in, speech):
    client = Client("https://fffiloni-dreamtalk.hf.space/")
    result = client.predict(
      speech, # filepath  in 'Audio input' Audio component
      image_in, # filepath  in 'Image' Image component
      "M030_front_neutral_level1_001.mat", # Literal['M030_front_angry_level3_001.mat', 'M030_front_contempt_level3_001.mat', 'M030_front_disgusted_level3_001.mat', 'M030_front_fear_level3_001.mat', 'M030_front_happy_level3_001.mat', 'M030_front_neutral_level1_001.mat', 'M030_front_sad_level3_001.mat', 'M030_front_surprised_level3_001.mat', 'W009_front_angry_level3_001.mat', 'W009_front_contempt_level3_001.mat', 'W009_front_disgusted_level3_001.mat', 'W009_front_fear_level3_001.mat', 'W009_front_happy_level3_001.mat', 'W009_front_neutral_level1_001.mat', 'W009_front_sad_level3_001.mat', 'W009_front_surprised_level3_001.mat', 'W011_front_angry_level3_001.mat', 'W011_front_contempt_level3_001.mat', 'W011_front_disgusted_level3_001.mat', 'W011_front_fear_level3_001.mat', 'W011_front_happy_level3_001.mat', 'W011_front_neutral_level1_001.mat', 'W011_front_sad_level3_001.mat', 'W011_front_surprised_level3_001.mat']  in 'emotional style' Dropdown component
      api_name="/infer"
    )
    print(result)
    return result['video']

st.title("✨️ AI Partner")
st.header("To create partner use sidebar (tap on ▶️ button on the left top)", divider="rainbow")
st.sidebar.title("✨ Your AI Girl 🔞")
st.sidebar.write("We will make a perfect talking girlfriend for you, just upload photo")
img_prompt = st.sidebar.file_uploader("Upload Image of your girl", type=["jpeg", "jpg", "png"])
gender = st.sidebar.selectbox(
    'What will be your partner gender?',
    ('Female', 'Male')
)
sumbit_btn = st.sidebar.button("✨ Create partner")
voice = None
female_voice = "female.mp3"
male_voice = "male.mp3"
if gender == 'Female':
    voice = female_voice
else:
    voice = male_voice

messages = st.container(height=300)
input_user = st.chat_input(placeholder='Enter message for your partner...')
 
if sumbit_btn:
    if input_user:
        answer = gptClient.create_completion("gpt3", f"Answer on this question as beautiful nice kind {gender}: " + input_user)
        print("Answer generated. Generating audio")
        output_audio = get_speech(input_user, answer)
        print("Audio generated. Generating video")
        output_video = get_dreamtalk(img_prompt, output_audio)
        print("Video Generating. Sending to user")

        user_msg = messages.chat_message("user")
        user_msg.write(input_user)
        partner_response = messages.chat_message("Partner", avatar=img_prompt)
        partner_response.video(output_video)