Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
# Load the text generation
|
| 5 |
generator = InferenceClient("mistralai/Codestral-22B-v0.1")
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Define examples
|
| 19 |
examples = [
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Load the text generation model
|
| 5 |
generator = InferenceClient("mistralai/Codestral-22B-v0.1")
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
+
try:
|
| 10 |
+
# Use the `text_generation` method correctly
|
| 11 |
+
result = generator.text_generation(
|
| 12 |
+
text, # Pass the text input directly
|
| 13 |
+
max_length=100,
|
| 14 |
+
num_return_sequences=1
|
| 15 |
+
)
|
| 16 |
+
# Extract and return the generated text
|
| 17 |
+
return result["generated_text"] if "generated_text" in result else "Error: No text generated."
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {e}"
|
| 20 |
|
| 21 |
# Define examples
|
| 22 |
examples = [
|