Spaces:
Runtime error
Runtime error
Quentin Gallouédec
commited on
Commit
·
bcba9c0
1
Parent(s):
1a49562
update app
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from huggingface_hub import HfApi, ModelFilter
|
|
|
4 |
|
5 |
# Get the list of models from the Hugging Face Hub
|
6 |
api = HfApi()
|
@@ -12,31 +13,41 @@ model_pipelines = {}
|
|
12 |
|
13 |
# Load a default model initially
|
14 |
default_model_name = "gia-project/gia2-small-untrained"
|
15 |
-
|
16 |
-
model_pipelines[default_model_name] = default_generator
|
17 |
|
18 |
def generate_text(model_name, input_text):
|
|
|
|
|
|
|
19 |
# Check if the selected model is already loaded
|
20 |
if model_name not in model_pipelines:
|
21 |
# Load the model and create a pipeline if it's not already loaded
|
22 |
generator = pipeline("text-generation", model=model_name, trust_remote_code=True)
|
23 |
model_pipelines[model_name] = generator
|
24 |
-
|
25 |
-
# Get the pipeline for the selected model
|
26 |
generator = model_pipelines[model_name]
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Define the Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
fn=generate_text, # Function to be called on user input
|
33 |
inputs=[
|
34 |
-
|
35 |
-
|
36 |
],
|
37 |
-
outputs=
|
38 |
title="GIA Text Generation", # Title of the interface
|
39 |
)
|
40 |
|
41 |
# Launch the Gradio interface
|
42 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio.components import Dropdown, Textbox
|
3 |
from huggingface_hub import HfApi, ModelFilter
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
# Get the list of models from the Hugging Face Hub
|
7 |
api = HfApi()
|
|
|
13 |
|
14 |
# Load a default model initially
|
15 |
default_model_name = "gia-project/gia2-small-untrained"
|
16 |
+
|
|
|
17 |
|
18 |
def generate_text(model_name, input_text):
|
19 |
+
# Inform the user that the model is loading
|
20 |
+
yield "Loading model..."
|
21 |
+
|
22 |
# Check if the selected model is already loaded
|
23 |
if model_name not in model_pipelines:
|
24 |
# Load the model and create a pipeline if it's not already loaded
|
25 |
generator = pipeline("text-generation", model=model_name, trust_remote_code=True)
|
26 |
model_pipelines[model_name] = generator
|
27 |
+
|
28 |
+
# Get the pipeline for the selected model
|
29 |
generator = model_pipelines[model_name]
|
30 |
+
|
31 |
+
# Inform the user that the text is being generated
|
32 |
+
yield "Generating text..."
|
33 |
+
|
34 |
+
# Generate text
|
35 |
+
generated_text = generator(input_text)[0]["generated_text"]
|
36 |
+
|
37 |
+
# Return the generated text
|
38 |
+
yield generated_text
|
39 |
+
|
40 |
|
41 |
# Define the Gradio interface
|
42 |
iface = gr.Interface(
|
43 |
fn=generate_text, # Function to be called on user input
|
44 |
inputs=[
|
45 |
+
Dropdown(models_names, label="Select Model", value="gia-project/gia2-small-untrained"), # Select model
|
46 |
+
Textbox(lines=5, label="Input Text"), # Textbox for entering text
|
47 |
],
|
48 |
+
outputs=Textbox(label="Generated Text"), # Textbox to display the generated text
|
49 |
title="GIA Text Generation", # Title of the interface
|
50 |
)
|
51 |
|
52 |
# Launch the Gradio interface
|
53 |
+
iface.launch(enable_queue=True)
|