aheedsajid commited on
Commit
87fe6e8
1 Parent(s): 70d626e

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +58 -0
  2. requirements.txt +8 -0
  3. style.css +3 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import gradio as gr
4
+ import edge_tts
5
+ import asyncio
6
+ import time
7
+ import tempfile
8
+ from huggingface_hub import InferenceClient
9
+
10
+ HF_TOKEN = os.environ.get("HF_TOKEN")
11
+
12
+ DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
13
+ ### <center>A personal Assistant of Tony Stark for YOU
14
+ ### <center>Currently It supports text input, But If this space completes 1k hearts than I starts working on Audio Input.</center>
15
+ """
16
+
17
+ client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1", hf_token=HF_TOKEN)
18
+
19
+ system_instructions1 = "[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]"
20
+
21
+ async def generate1(prompt):
22
+ generate_kwargs = dict(
23
+ temperature=0.6,
24
+ max_new_tokens=256,
25
+ top_p=0.95,
26
+ repetition_penalty=1,
27
+ do_sample=True,
28
+ seed=42,
29
+ )
30
+ formatted_prompt = system_instructions1 + prompt + "[JARVIS]"
31
+ stream = client1.text_generation(
32
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
33
+ output = ""
34
+ for response in stream:
35
+ output += response.token.text
36
+
37
+ communicate = edge_tts.Communicate(output)
38
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
39
+ tmp_path = tmp_file.name
40
+ await communicate.save(tmp_path)
41
+ yield tmp_path
42
+
43
+ with gr.Blocks(css="style.css") as demo:
44
+ gr.Markdown(DESCRIPTION)
45
+ with gr.Row():
46
+ user_input = gr.Textbox(label="Prompt", value="What is Wikipedia")
47
+ input_text = gr.Textbox(label="Input Text", elem_id="important")
48
+ output_audio = gr.Audio(label="JARVIS", type="filepath",
49
+ interactive=False,
50
+ autoplay=True,
51
+ elem_classes="audio")
52
+ with gr.Row():
53
+ translate_btn = gr.Button("Response")
54
+ translate_btn.click(fn=generate1, inputs=user_input,
55
+ outputs=output_audio, api_name="translate")
56
+
57
+ if __name__ == "__main__":
58
+ demo.queue(max_size=200).launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ edge-tts
2
+ gradio
3
+ asyncio
4
+ transformers
5
+ torch
6
+ audiosegment
7
+ scipy
8
+ librosa
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #important{
2
+ display: none;
3
+ }