Update
Browse files
app.py
CHANGED
|
@@ -1,10 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|