Spaces:
Runtime error
Runtime error
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
model_name = "mistralai/Codestral-22B-v0.1"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def generate_text(prompt, max_length=1000, min_length=50, temperature=0.1):
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
outputs = model.generate(
|
11 |
+
inputs['input_ids'],
|
12 |
+
max_length=max_length,
|
13 |
+
min_length=min_length,
|
14 |
+
temperature=temperature
|
15 |
+
)
|
16 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
+
return response
|
18 |
+
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=generate_text,
|
21 |
+
inputs=[
|
22 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
23 |
+
gr.inputs.Slider(minimum=10, maximum=2000, default=1000, label="Max Length"),
|
24 |
+
gr.inputs.Slider(minimum=10, maximum=100, default=50, label="Min Length"),
|
25 |
+
gr.inputs.Slider(minimum=0.1, maximum=1, default=0.1, label="Temperature")
|
26 |
+
],
|
27 |
+
outputs="text",
|
28 |
+
title="Text Generation with Mistralai",
|
29 |
+
description="Generate text using the mistralai/Codestral-22B-v0.1 model."
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
interface.launch()
|