Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,15 @@ generator = InferenceClient("mistralai/Codestral-22B-v0.1")
|
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
try:
|
| 10 |
-
#
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
return f"Error: {e}"
|
| 20 |
|
|
|
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
try:
|
| 10 |
+
# Generate text using the correct API call
|
| 11 |
+
result = generator.text_generation(text, details=True, stream=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Extract and return the generated text
|
| 13 |
+
if "generated_text" in result:
|
| 14 |
+
return result["generated_text"]
|
| 15 |
+
elif isinstance(result, list) and len(result) > 0:
|
| 16 |
+
return result[0] # If the response is a list, return the first item
|
| 17 |
+
else:
|
| 18 |
+
return "Error: Unable to generate text."
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error: {e}"
|
| 21 |
|