File size: 2,434 Bytes
52811e4
c9ca579
52811e4
 
cbf4cd7
383cfb9
cbf4cd7
383cfb9
 
 
 
 
 
 
 
 
 
 
cbf4cd7
 
383cfb9
 
 
 
 
 
 
 
 
 
52811e4
 
dc8adce
c9ca579
 
52811e4
 
336ed2f
 
 
52811e4
 
 
 
9a6e691
52811e4
 
 
 
 
336ed2f
 
5342861
 
 
 
 
 
383cfb9
 
 
c9ca579
 
68bde08
 
 
 
 
 
 
 
c9ca579
 
 
68bde08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
import gradio as gr
from huggingface_hub import InferenceClient

client2 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")

system_instructions2 = "[SYSTEM] You are the Best AI, you can solve complex problems you answer in short , simple and easy language.[USER]"

def text(prompt):
    generate_kwargs = dict(
        temperature=0.5,
        max_new_tokens=5,
        top_p=0.7,
        repetition_penalty=1.2,
        do_sample=True,
        seed=42,
    )

    formatted_prompt = system_instructions2 + prompt + "[BOT]"
    stream = client2.text_generation(
        formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
    output = ""

    for response in stream:
        if not response.token.text == "</s>":
            output += response.token.text

    return output  


client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")

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]"

def classify_task(prompt):
    generate_kwargs = dict(
        temperature=0.5,
        max_new_tokens=5,
        top_p=0.7,
        repetition_penalty=1.2,
        do_sample=True,
        seed=42,
    )

    formatted_prompt = system_instructions + prompt + "[BOT]"
    stream = client.text_generation(
        formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
    output = ""

    for response in stream:
        if not response.token.text == "</s>":
            output += response.token.text
            if 'text' in output.lower():
                user = text(prompt)
            elif 'image' in output.lower():
                return 'Image Generation'
            else:
                return 'Unknown Task'




# Create the Gradio interface
with gr.Blocks() as demo:
    with gr.Row():
        text_uesr_input = gr.Textbox(label="Enter text 📚")
        output = gr.Textbox(label="Translation")
    with gr.Row():
        translate_btn = gr.Button("Translate 🚀")
        translate_btn.click(fn=classify_task, inputs=text_uesr_input,
                            outputs=output, api_name="translate_text")

# Launch the app
if __name__ == "__main__":
    demo.launch()