Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
# Load the text generation
|
| 5 |
-
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
try:
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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 |
|
| 22 |
# Define examples
|
| 23 |
examples = [
|
| 24 |
-
["
|
| 25 |
-
["
|
| 26 |
-
["What is
|
| 27 |
-
["Describe
|
| 28 |
]
|
| 29 |
|
| 30 |
# Create the Gradio interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the text generation pipeline
|
| 5 |
+
pipe = pipeline("text-generation", model="mistralai/Codestral-22B-v0.1")
|
| 6 |
|
| 7 |
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
try:
|
| 10 |
+
# Format the input and generate text
|
| 11 |
+
messages = [{"role": "user", "content": text}]
|
| 12 |
+
result = pipe(messages, max_length=100, num_return_sequences=1)
|
| 13 |
+
# Extract the generated text
|
| 14 |
+
return result[0]['generated_text'] if result else "Error: No text generated."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
return f"Error: {e}"
|
| 17 |
|
| 18 |
# Define examples
|
| 19 |
examples = [
|
| 20 |
+
["Who are you?"],
|
| 21 |
+
["Explain the difference between AI and ML."],
|
| 22 |
+
["What is overfitting in machine learning?"],
|
| 23 |
+
["Describe transfer learning and its importance."]
|
| 24 |
]
|
| 25 |
|
| 26 |
# Create the Gradio interface
|