Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,10 @@ from huggingface_hub import InferenceClient
|
|
3 |
from transformers import pipeline
|
4 |
from typing import List, Tuple # Importing for type annotations
|
5 |
|
6 |
-
# Initialize
|
7 |
-
|
8 |
|
9 |
-
# Function to handle the response generation using
|
10 |
def respond(
|
11 |
message: str,
|
12 |
history: List[Tuple[str, str]], # Using List and Tuple for type annotation
|
@@ -29,17 +29,14 @@ def respond(
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
-
#
|
33 |
-
for
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
token = message.choices[0].delta.content
|
41 |
-
response += token
|
42 |
-
yield response
|
43 |
|
44 |
|
45 |
# Setting up Gradio Interface
|
|
|
3 |
from transformers import pipeline
|
4 |
from typing import List, Tuple # Importing for type annotations
|
5 |
|
6 |
+
# Initialize the BERT model pipeline for the "fill-mask" task
|
7 |
+
pipe = pipeline("fill-mask", model="bert-base-uncased")
|
8 |
|
9 |
+
# Function to handle the response generation using BERT
|
10 |
def respond(
|
11 |
message: str,
|
12 |
history: List[Tuple[str, str]], # Using List and Tuple for type annotation
|
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
+
# Using the BERT pipeline to fill the mask (this is different from the GPT-style completion)
|
33 |
+
# BERT doesn't generate text the same way, so we are simulating a response for this demo
|
34 |
+
result = pipe(f"Hello, how are you today? {message} [MASK]")
|
35 |
+
|
36 |
+
# Collecting the filled-in mask (likely output from BERT's "fill-mask" task)
|
37 |
+
response = result[0]['sequence']
|
38 |
+
|
39 |
+
yield response
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
# Setting up Gradio Interface
|