KingNish commited on
Commit
383cfb9
1 Parent(s): dc8adce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -2,6 +2,32 @@ import re
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
6
 
7
  system_instructions = "[SYSTEM] You will be provided with text, and your task is to classify task tasks are (text generation, image generation, tts) answer with only task type that prompt user give, do not say anything else and stop as soon as possible. Example: User- What is friction , BOT - text generation [USER]"
@@ -25,7 +51,17 @@ def classify_task(prompt):
25
  if not response.token.text == "</s>":
26
  output += response.token.text
27
 
28
- return output
 
 
 
 
 
 
 
 
 
 
29
 
30
  # Create the Gradio interface
31
  with gr.Blocks() as demo:
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
6
+
7
+ system_instructions = "[SYSTEM] You are the Best AI, you can solve complex problems you answer in short , simple and easy language.[USER]"
8
+
9
+ def text(prompt):
10
+ generate_kwargs = dict(
11
+ temperature=0.5,
12
+ max_new_tokens=5,
13
+ top_p=0.7,
14
+ repetition_penalty=1.2,
15
+ do_sample=True,
16
+ seed=42,
17
+ )
18
+
19
+ formatted_prompt = system_instructions + prompt + "[BOT]"
20
+ stream = client.text_generation(
21
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
22
+ output = ""
23
+
24
+ for response in stream:
25
+ if not response.token.text == "</s>":
26
+ output += response.token.text
27
+
28
+ return output
29
+
30
+
31
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
32
 
33
  system_instructions = "[SYSTEM] You will be provided with text, and your task is to classify task tasks are (text generation, image generation, tts) answer with only task type that prompt user give, do not say anything else and stop as soon as possible. Example: User- What is friction , BOT - text generation [USER]"
 
51
  if not response.token.text == "</s>":
52
  output += response.token.text
53
 
54
+ yield output
55
+
56
+ if 'text' in output.lower():
57
+ user = text(prompt)
58
+ elif 'image' in output.lower():
59
+ return 'Image Generation'
60
+ else:
61
+ return 'Unknown Task'
62
+
63
+
64
+
65
 
66
  # Create the Gradio interface
67
  with gr.Blocks() as demo: