Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
gr.load("models/mistralai/Mistral-Nemo-Instruct-2407").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
gr.load("models/mistralai/Mistral-Nemo-Instruct-2407").launch()
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import torch
|
7 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
8 |
+
|
9 |
+
# Load pre-trained BlackMamba model and tokenizer
|
10 |
+
model_name = "blackmamba"
|
11 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
12 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
13 |
+
|
14 |
+
def generate_text(prompt, max_length=50):
|
15 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
16 |
+
outputs = model.generate(inputs, max_length=max_length, num_return_sequences=1)
|
17 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return generated_text
|
19 |
+
|
20 |
+
# Create Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=generate_text,
|
23 |
+
inputs="text",
|
24 |
+
outputs="text",
|
25 |
+
title="WormGPT",
|
26 |
+
description="An evil brother of ChatGPT for Hugging Face Gradio"
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the interface
|
30 |
+
iface.launch()
|