jordigonzm commited on
Commit
82cc52b
1 Parent(s): 95a989a

Load the model using Hugging Face's transformers pipeline

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import gradio as gr
 
2
 
3
- # Load the model outside the main function to ensure it is only loaded once
4
- model = gr.Interface.load("microsoft/Phi-3-mini-128k-instruct")
 
5
 
6
- def chat_with_model(prompt):
7
- # Directly use the model's prediction function
8
- return model(prompt)
 
9
 
10
- def main():
11
  with gr.Blocks() as blocks:
12
  with gr.Tab("Model Info"):
13
  gr.Markdown("""
@@ -22,11 +24,10 @@ def main():
22
  The information provided should not be seen as a modification of the licensing under which the model is released.
23
  [More information](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct)
24
  """)
25
- with gr.Tab("Chat"):
26
- with gr.Row():
27
- input_text = gr.Textbox(placeholder="Type here to talk to the model")
28
- output_text = gr.Textbox(label="Model Response")
29
- input_text.change(fn=chat_with_model, inputs=input_text, outputs=output_text)
30
 
31
  blocks.launch()
32
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ def main():
5
+ # Load the model using Hugging Face's transformers pipeline
6
+ model = pipeline("text-generation", model="microsoft/Phi-3-mini-128k-instruct")
7
 
8
+ def generate_text(input_text):
9
+ # Generate text using the model
10
+ result = model(input_text, max_length=50)
11
+ return result[0]['generated_text']
12
 
 
13
  with gr.Blocks() as blocks:
14
  with gr.Tab("Model Info"):
15
  gr.Markdown("""
 
24
  The information provided should not be seen as a modification of the licensing under which the model is released.
25
  [More information](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct)
26
  """)
27
+ with gr.Tab("Generate Text"):
28
+ input_text = gr.Textbox(placeholder="Type here to generate text")
29
+ output_text = gr.Textbox(label="Generated Text")
30
+ input_text.submit(fn=generate_text, inputs=input_text, outputs=output_text)
 
31
 
32
  blocks.launch()
33