paloma99 commited on
Commit
1674572
1 Parent(s): 972c635

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
 
5
- # Image Classification Model
6
  image_pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
7
 
8
  def predict_image(input_img):
@@ -16,7 +16,7 @@ image_gradio_app = gr.Interface(
16
  title="Hot Dog? Or Not?",
17
  )
18
 
19
- # Chatbot Model
20
  tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
21
  chatbot_model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
22
 
@@ -29,17 +29,17 @@ def predict_chatbot(input, history=[]):
29
  response_tuples = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)]
30
  return response_tuples, history
31
 
32
- chatbot_gradio_app = gr.Blocks()
33
- with chatbot_gradio_app as demo:
34
- chatbot = gr.Chatbot()
35
- state = gr.State([])
36
- with gr.Row():
37
- txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
38
- txt.submit(predict_chatbot, [txt, state], [chatbot, state])
39
-
40
- # Launch both interfaces
41
- if __name__ == "__main__":
42
- gr.Interface(
43
- columns=2,
44
- children=[image_gradio_app, chatbot_gradio_app]
45
- ).launch()
 
2
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
 
5
+ # Cell 1: Image Classification Model
6
  image_pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
7
 
8
  def predict_image(input_img):
 
16
  title="Hot Dog? Or Not?",
17
  )
18
 
19
+ # Cell 2: Chatbot Model
20
  tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
21
  chatbot_model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
22
 
 
29
  response_tuples = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)]
30
  return response_tuples, history
31
 
32
+ chatbot_gradio_app = gr.Interface(
33
+ fn=predict_chatbot,
34
+ inputs=gr.Textbox(show_label=False, placeholder="Enter text and press enter"),
35
+ outputs=gr.Textbox(),
36
+ live=True,
37
+ title="Chatbot",
38
+ )
39
+
40
+
41
+ # Combine both interfaces into a single app
42
+ gr.TabbedInterface(
43
+ [image_gradio_app, chatbot_gradio_app],
44
+ tab_names=["image","chatbot"]
45
+ ).launch()