Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,23 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
-
|
5 |
-
|
6 |
-
try:
|
7 |
-
model_name = "tiiuae/falcon-40b-instruct" # Ensure this is the correct model name
|
8 |
-
nlp_model = pipeline('text-generation', model=model_name, trust_remote_code=True) # Added trust_remote_code=True
|
9 |
-
print("Model loaded successfully.")
|
10 |
-
except Exception as e:
|
11 |
-
nlp_model = None
|
12 |
-
print(f"Failed to load model: {str(e)}")
|
13 |
|
14 |
def generate_text(prompt):
|
15 |
-
|
16 |
-
|
17 |
-
try:
|
18 |
-
response = nlp_model(prompt, max_length=50, num_return_sequences=1)
|
19 |
-
return response[0]['generated_text']
|
20 |
-
except Exception as e:
|
21 |
-
return f"Error during model inference: {str(e)}"
|
22 |
-
else:
|
23 |
-
return "Model could not be loaded or initialized properly."
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
)
|
|
|
|
|
33 |
|
34 |
-
# Essential for Hugging Face Spaces
|
35 |
if __name__ == "__main__":
|
36 |
-
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
+
import gradio as gr
|
5 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_text(prompt):
|
8 |
+
generator = pipeline('text-generation', model='tiiuae/falcon-40b-instruct', trust_remote_code=True)
|
9 |
+
return generator(prompt, max_length=100)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def main():
|
12 |
+
interface = gr.Interface(
|
13 |
+
fn=generate_text,
|
14 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your prompt here..."),
|
15 |
+
outputs="text",
|
16 |
+
title="Text Generation Model",
|
17 |
+
description="This model generates text based on the input prompt. Powered by Hugging Face transformers."
|
18 |
+
)
|
19 |
+
|
20 |
+
interface.launch()
|
21 |
|
|
|
22 |
if __name__ == "__main__":
|
23 |
+
main()
|