pokeberrypie commited on
Commit
e55a05c
·
verified ·
1 Parent(s): 4c3f45f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -28
app.py CHANGED
@@ -1,36 +1,23 @@
1
  import os
2
  import gradio as gr
3
  from transformers import pipeline
4
-
5
- # Initialize the model
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
- """Generate text based on the input prompt using the loaded NLP model."""
16
- if nlp_model:
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
- # Setup Gradio interface
26
- iface = gr.Interface(
27
- fn=generate_text,
28
- inputs=gr.Textbox(lines=2, placeholder="Enter your text here..."),
29
- outputs="text",
30
- title="Text Generation with Falcon Model",
31
- description="Enter some text and see how the Falcon model continues it! This model automatically generates text based on the input provided. Try it out!"
32
- )
 
 
33
 
34
- # Essential for Hugging Face Spaces
35
  if __name__ == "__main__":
36
- iface.launch(share=True)
 
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()