iDrops commited on
Commit
9ef73e4
·
verified ·
1 Parent(s): 71426cd

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +54 -0
App.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ DESCRIPTION = """ # <center><b>ASTIG⚡</b></center>
11
+ """
12
+
13
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
14
+
15
+ system_instructions = "[INST] Answer as Real ASTIG a better version of JARVIS, Made by 'Dave Miracle', Keep conversation very short, clear, friendly and concise."
16
+
17
+ async def generate(prompt):
18
+ generate_kwargs = dict(
19
+ temperature=0.6,
20
+ max_new_tokens=256,
21
+ top_p=0.95,
22
+ repetition_penalty=1,
23
+ do_sample=True,
24
+ seed=42,
25
+ )
26
+ formatted_prompt = system_instructions + prompt + "[/INST]"
27
+ stream = client.text_generation(
28
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
29
+ output = ""
30
+ for response in stream:
31
+ output += response.token.text
32
+
33
+ communicate = edge_tts.Communicate(output)
34
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
35
+ tmp_path = tmp_file.name
36
+ await communicate.save(tmp_path)
37
+ yield tmp_path
38
+
39
+ with gr.Blocks(css="style.css") as demo:
40
+ gr.Markdown(DESCRIPTION)
41
+ with gr.Row():
42
+ user_input = gr.Textbox(label="Prompt")
43
+ input_text = gr.Textbox(label="Input Text", elem_id="important")
44
+ output_audio = gr.Audio(label="Audio", type="filepath",
45
+ interactive=False,
46
+ autoplay=True,
47
+ elem_classes="audio")
48
+ with gr.Row():
49
+ translate_btn = gr.Button("Response")
50
+ translate_btn.click(fn=generate, inputs=user_input,
51
+ outputs=output_audio, api_name="translate")
52
+
53
+ if __name__ == "__main__":
54
+ demo.queue(max_size=20).launch()