Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
# Load the text generation pipeline
|
| 5 |
-
generator =
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Define examples
|
| 13 |
examples = [
|
|
@@ -26,4 +32,5 @@ run = gr.Interface(
|
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch the app
|
| 29 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
# Load the text generation pipeline
|
| 5 |
+
generator = InferenceClient("mistralai/Codestral-22B-v0.1")
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
+
# Use the `text_generation` method for generating text
|
| 10 |
+
result = generator.text_generation(
|
| 11 |
+
inputs=text,
|
| 12 |
+
max_length=100,
|
| 13 |
+
num_return_sequences=1
|
| 14 |
+
)
|
| 15 |
+
# Extract and return the generated text
|
| 16 |
+
return result[0]['generated_text'] if 'generated_text' in result[0] else "Error: Failed to generate text"
|
| 17 |
|
| 18 |
# Define examples
|
| 19 |
examples = [
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
# Launch the app
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
run.launch()
|