KingNish commited on
Commit
8e90be2
1 Parent(s): ace0051

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -7
app.py CHANGED
@@ -12,11 +12,22 @@ DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
12
  ### <center>Currently It supports text input, But If this space completes 1k hearts than I starts working on Audio Input.</center>
13
  """
14
 
15
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
 
 
 
 
 
 
 
 
 
16
 
17
- system_instructions = "[INST] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Keep conversation very short, clear, friendly and concise."
18
 
19
- async def generate(prompt):
 
 
20
  generate_kwargs = dict(
21
  temperature=0.6,
22
  max_new_tokens=256,
@@ -25,8 +36,58 @@ async def generate(prompt):
25
  do_sample=True,
26
  seed=42,
27
  )
28
- formatted_prompt = system_instructions + prompt + "[/INST]"
29
- stream = client.text_generation(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
31
  output = ""
32
  for response in stream:
@@ -40,6 +101,33 @@ async def generate(prompt):
40
 
41
  with gr.Blocks(css="style.css") as demo:
42
  gr.Markdown(DESCRIPTION)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  with gr.Row():
44
  user_input = gr.Textbox(label="Prompt")
45
  input_text = gr.Textbox(label="Input Text", elem_id="important")
@@ -49,8 +137,10 @@ with gr.Blocks(css="style.css") as demo:
49
  elem_classes="audio")
50
  with gr.Row():
51
  translate_btn = gr.Button("Response")
52
- translate_btn.click(fn=generate, inputs=user_input,
53
- outputs=output_audio, api_name="translate")
 
 
54
 
55
  if __name__ == "__main__":
56
  demo.queue(max_size=20).launch()
 
12
  ### <center>Currently It supports text input, But If this space completes 1k hearts than I starts working on Audio Input.</center>
13
  """
14
 
15
+ MORE = """ ## TRY Other Models
16
+ ### Instant Video: Create Amazing Videos in 5 Second -> https://huggingface.co/spaces/KingNish/Instant-Video
17
+ ### Instant Image: 4k images in 5 Second -> https://huggingface.co/spaces/KingNish/Instant-Image
18
+ """
19
+
20
+ Fast = """## Fastest Model"""
21
+
22
+ Complex = """## Best in Complex Question"""
23
+
24
+ Detail = """## Best for Detailed Generation or Long Answers"""
25
 
26
+ client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
27
 
28
+ system_instructions1 = "[INST] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Keep conversation very short, clear, friendly and concise."
29
+
30
+ async def generate1(prompt):
31
  generate_kwargs = dict(
32
  temperature=0.6,
33
  max_new_tokens=256,
 
36
  do_sample=True,
37
  seed=42,
38
  )
39
+ formatted_prompt = system_instructions1 + prompt + "[/INST]"
40
+ stream = client1.text_generation(
41
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
42
+ output = ""
43
+ for response in stream:
44
+ output += response.token.text
45
+
46
+ communicate = edge_tts.Communicate(output)
47
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
48
+ tmp_path = tmp_file.name
49
+ await communicate.save(tmp_path)
50
+ yield tmp_path
51
+
52
+ client2 = InferenceClient("microsoft/Phi-3-mini-4k-instruct")
53
+
54
+ system_instructions2 = "[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Must answer in friendly style, You can answer Complex Questions. Do not say who are you or Hi, Hello, Just Start answering. Stop, as answer ends. [USER]"
55
+
56
+ async def generate2(prompt):
57
+ generate_kwargs = dict(
58
+ temperature=0.6,
59
+ max_new_tokens=512,
60
+ top_p=0.95,
61
+ repetition_penalty=1,
62
+ do_sample=True,
63
+ )
64
+ formatted_prompt = system_instructions2 + prompt + "[ASSISTANT]"
65
+ stream = client2.text_generation(
66
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
67
+ output = ""
68
+ for response in stream:
69
+ output += response.token.text
70
+
71
+ communicate = edge_tts.Communicate(output)
72
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
73
+ tmp_path = tmp_file.name
74
+ await communicate.save(tmp_path)
75
+ yield tmp_path
76
+
77
+ client3 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
78
+
79
+ system_instructions3 = "[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Must answer in detailed and friendly. Do not say who are you or Hi, Hello, Just Start answering. You answers all things in detail.[USER]"
80
+
81
+ async def generate3(prompt):
82
+ generate_kwargs = dict(
83
+ temperature=0.6,
84
+ max_new_tokens=2048,
85
+ top_p=0.95,
86
+ repetition_penalty=1,
87
+ do_sample=True,
88
+ )
89
+ formatted_prompt = system_instructions3 + prompt + "[ASSISTANT]"
90
+ stream = client3.text_generation(
91
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
92
  output = ""
93
  for response in stream:
 
101
 
102
  with gr.Blocks(css="style.css") as demo:
103
  gr.Markdown(DESCRIPTION)
104
+ gr.Markdown(Fast)
105
+ with gr.Row():
106
+ user_input = gr.Textbox(label="Prompt")
107
+ input_text = gr.Textbox(label="Input Text", elem_id="important")
108
+ output_audio = gr.Audio(label="Audio", type="filepath",
109
+ interactive=False,
110
+ autoplay=True,
111
+ elem_classes="audio")
112
+ with gr.Row():
113
+ translate_btn = gr.Button("Response")
114
+ translate_btn.click(fn=generate1, inputs=user_input,
115
+ outputs=output_audio, api_name="translate")
116
+
117
+ gr.Markdown(Complex)
118
+ with gr.Row():
119
+ user_input = gr.Textbox(label="Prompt")
120
+ input_text = gr.Textbox(label="Input Text", elem_id="important")
121
+ output_audio = gr.Audio(label="Audio", type="filepath",
122
+ interactive=False,
123
+ autoplay=True,
124
+ elem_classes="audio")
125
+ with gr.Row():
126
+ translate_btn = gr.Button("Response")
127
+ translate_btn.click(fn=generate2, inputs=user_input,
128
+ outputs=output_audio, api_name="translate")
129
+
130
+ gr.Markdown(Detail)
131
  with gr.Row():
132
  user_input = gr.Textbox(label="Prompt")
133
  input_text = gr.Textbox(label="Input Text", elem_id="important")
 
137
  elem_classes="audio")
138
  with gr.Row():
139
  translate_btn = gr.Button("Response")
140
+ translate_btn.click(fn=generate3, inputs=user_input,
141
+ outputs=output_audio, api_name="translate")
142
+
143
+ gr.Markdown(MORE)
144
 
145
  if __name__ == "__main__":
146
  demo.queue(max_size=20).launch()