Huzaifa367 commited on
Commit
1869fec
·
verified ·
1 Parent(s): 9813dcd

Create jarvis.py

Browse files
Files changed (1) hide show
  1. pages/jarvis.py +49 -0
pages/jarvis.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import edge_tts
4
+ import tempfile
5
+ import os
6
+
7
+ # Initialize voice chat pipeline and other settings
8
+ default_lang = "en"
9
+ 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]"
10
+ client = pipeline("text2text-generation", model="mistralai/Mixtral-8x7B-Instruct-v0.1")
11
+
12
+ # Function to transcribe audio
13
+ def transcribe(audio):
14
+ lang = "en"
15
+ text = "Sample transcription" # Replace with your transcription logic
16
+ return text
17
+
18
+ # Function to generate Jarvis response
19
+ def generate_jarvis_response(prompt):
20
+ formatted_prompt = system_instructions + prompt + "[JARVIS]"
21
+ output = client(formatted_prompt)
22
+ response_text = output[0]['generated_text']
23
+ communicate = edge_tts.Communicate(response_text)
24
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
25
+ tmp_path = tmp_file.name
26
+ communicate.save(tmp_path)
27
+ return tmp_path
28
+
29
+ # Streamlit UI
30
+ st.title("JARVIS⚡ - Personal Assistant of Tony Stark")
31
+ st.markdown("Voice Chat with your personal assistant")
32
+
33
+ # Voice chat interface
34
+ audio_file = st.file_uploader("Voice Chat (BETA) - Upload audio file", type=["mp3", "wav"])
35
+ if audio_file:
36
+ audio_path = transcribe(audio_file)
37
+ response_path = generate_jarvis_response(audio_path)
38
+ st.audio(response_path)
39
+
40
+ # Text-based interaction
41
+ st.markdown("### Text-based Interaction")
42
+ prompt_text = st.text_input("Prompt", "What is Wikipedia?")
43
+ if st.button("Generate Response"):
44
+ response_path = generate_jarvis_response(prompt_text)
45
+ st.audio(response_path)
46
+
47
+ # # Additional links
48
+ # st.markdown("### Try Other Models")
49
+ # st.markdown("[Instant ](https://huggingface.co/spaces/)")