Ankit93 commited on
Commit
70a0c8f
·
verified ·
1 Parent(s): 41146ef
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -1,10 +1,31 @@
1
  import gradio as gr
 
2
 
3
- with gr.Blocks(fill_height=True) as demo:
4
- with gr.Sidebar():
5
- gr.Markdown("# Inference Provider")
6
- gr.Markdown("This Space showcases the mistralai/Mixtral-8x7B-Instruct-v0.1 model, served by the hf-inference API. Sign in with your Hugging Face account to use this API.")
7
- button = gr.LoginButton("Sign in")
8
- gr.load("models/mistralai/Mixtral-8x7B-Instruct-v0.1", accept_token=button, provider="hf-inference")
9
-
10
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Initialize the model pipeline only once
5
+ text_generator = pipeline("text-generation", model="mistralai/Mixtral-8x7B-Instruct-v0.1", device_map="auto")
6
+
7
+ class Inference:
8
+ def __init__(self, pipe):
9
+ self.pipe = pipe
10
+
11
+ def get_results(self, prompt, max_new_tokens=256, temperature=0.7):
12
+ output = self.pipe(prompt, max_new_tokens=max_new_tokens, temperature=temperature)
13
+ return output[0]["generated_text"]
14
+
15
+ inference = Inference(text_generator)
16
+
17
+ def generate_text(prompt, max_tokens, temperature):
18
+ return inference.get_results(prompt, max_tokens, temperature)
19
+
20
+ # Create a simple Gradio interface
21
+ gr.Interface(
22
+ fn=generate_text,
23
+ inputs=[
24
+ gr.Textbox(lines=4, label="Prompt"),
25
+ gr.Slider(minimum=10, maximum=1024, value=256, label="Max New Tokens"),
26
+ gr.Slider(minimum=0.1, maximum=1.5, value=0.7, step=0.1, label="Temperature"),
27
+ ],
28
+ outputs=gr.Textbox(label="Generated Text"),
29
+ title="Mixtral-8x7B Text Generator",
30
+ description="Enter a prompt to generate text using Mixtral-8x7B-Instruct."
31
+ ).launch()