File size: 2,258 Bytes
1869fec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline
import edge_tts
import tempfile
import os

# Initialize voice chat pipeline and other settings
default_lang = "en"
system_instructions = "[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses as if You are the character Jarvis, made by 'Tony Stark.' The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant. [USER]"
client = pipeline("text2text-generation", model="mistralai/Mixtral-8x7B-Instruct-v0.1")

# Function to transcribe audio
def transcribe(audio):
    lang = "en"
    text = "Sample transcription"  # Replace with your transcription logic
    return text

# Function to generate Jarvis response
def generate_jarvis_response(prompt):
    formatted_prompt = system_instructions + prompt + "[JARVIS]"
    output = client(formatted_prompt)
    response_text = output[0]['generated_text']
    communicate = edge_tts.Communicate(response_text)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
        tmp_path = tmp_file.name
        communicate.save(tmp_path)
    return tmp_path

# Streamlit UI
st.title("JARVIS⚡ - Personal Assistant of Tony Stark")
st.markdown("Voice Chat with your personal assistant")

# Voice chat interface
audio_file = st.file_uploader("Voice Chat (BETA) - Upload audio file", type=["mp3", "wav"])
if audio_file:
    audio_path = transcribe(audio_file)
    response_path = generate_jarvis_response(audio_path)
    st.audio(response_path)

# Text-based interaction
st.markdown("### Text-based Interaction")
prompt_text = st.text_input("Prompt", "What is Wikipedia?")
if st.button("Generate Response"):
    response_path = generate_jarvis_response(prompt_text)
    st.audio(response_path)

# # Additional links
# st.markdown("### Try Other Models")
# st.markdown("[Instant ](https://huggingface.co/spaces/)")