Spaces:
Running
Running
test with google/flan-t5-small
Browse files
app.py
CHANGED
@@ -1,20 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
#client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B")
|
9 |
-
#client = InferenceClient("microsoft/MAI-DS-R1") ERROR
|
10 |
-
#client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct") ERROR
|
11 |
-
#client = InferenceClient("nvidia/Nemotron-H-47B-Base-8K") ERROR
|
12 |
-
#client = InferenceClient("meta-llama/Llama-3.2-1B") TIMES OUT
|
13 |
-
#client = InferenceClient("CohereLabs/c4ai-command-a-03-2025") ERROR
|
14 |
-
#client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct") TIMES OUT
|
15 |
-
#client = InferenceClient("meta-llama/Llama-3.2-1B-Instruct") TIMES OUT
|
16 |
-
client = InferenceClient(model="prompthero/openjourney-v4")
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
def respond(
|
20 |
message,
|
@@ -35,20 +24,18 @@ def respond(
|
|
35 |
|
36 |
messages.append({"role": "user", "content": message})
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
for message in
|
41 |
-
|
42 |
-
|
43 |
-
stream=True,
|
44 |
-
temperature=temperature,
|
45 |
-
top_p=top_p,
|
46 |
-
):
|
47 |
-
token = message.choices[0].delta.content
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
|
|
|
52 |
|
53 |
"""
|
54 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Initialize the T5 model and tokenizer
|
5 |
+
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")
|
7 |
|
8 |
def respond(
|
9 |
message,
|
|
|
24 |
|
25 |
messages.append({"role": "user", "content": message})
|
26 |
|
27 |
+
# Create a prompt for the T5 model
|
28 |
+
prompt = "translate English to Italian: "
|
29 |
+
for message in messages:
|
30 |
+
prompt += message["content"] + " "
|
31 |
+
prompt = prompt.strip()
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Generate a response using the T5 model
|
34 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
35 |
+
outputs = model.generate(input_ids, max_length=max_tokens, temperature=temperature, top_p=top_p)
|
36 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
37 |
|
38 |
+
return response
|
39 |
|
40 |
"""
|
41 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|