Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,41 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
import gradio as gr
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
)
|
17 |
|
18 |
-
|
|
|
|
1 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
2 |
+
from gradio import gr
|
3 |
|
4 |
+
MODEL_NAME = "allenai/cosmo-xl"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
7 |
|
|
|
8 |
|
9 |
+
def generate_text(situation, instructions, prompt):
|
10 |
+
"""
|
11 |
+
Generate text using the specified model and inputs.
|
12 |
|
13 |
+
Args:
|
14 |
+
situation: A short description of the context or situation.
|
15 |
+
instructions: Specific instructions or constraints for text generation.
|
16 |
+
prompt: The initial text prompt for the model to start from.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
The generated text.
|
20 |
+
"""
|
21 |
+
inputs = tokenizer([situation, instructions, prompt], return_tensors="pt")
|
22 |
+
outputs = model.generate(**inputs)
|
23 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
+
return generated_text
|
25 |
+
|
26 |
+
|
27 |
+
interface = gr.Interface(
|
28 |
+
generate_text,
|
29 |
+
[
|
30 |
+
gr.Textbox(label="Situation"),
|
31 |
+
gr.Textbox(label="Instructions"),
|
32 |
+
gr.Textbox(label="Prompt"),
|
33 |
+
],
|
34 |
+
"textbox",
|
35 |
+
theme="huggingface",
|
36 |
+
title="Cosmopolitan Conversationalist",
|
37 |
+
description="Generate creative text with context and instructions!",
|
38 |
)
|
39 |
|
40 |
+
interface.launch(server_name="Cosmopolitan_Conversationalist")
|
41 |
+
|