joys631 commited on
Commit
7d29a02
1 Parent(s): 76a1fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -12
app.py CHANGED
@@ -1,18 +1,41 @@
1
- #import gradio as gr
 
2
 
3
- #gr.load("models/allenai/cosmo-xl")
 
 
4
 
5
- import gradio as gr
6
 
7
- def echo_with_inputs(message, history, additional_input):
8
- return f"You said: {message}\nAdditional input: {additional_input}"
 
9
 
10
- demo = gr.ChatInterface(
11
- fn=echo_with_inputs,
12
- examples=["hello", "hola", "merhaba"],
13
- title="Echo Bot with Inputs",
14
- inputs=["textbox", "textbox"],
15
- labels=["Message", "Additional Input"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  )
17
 
18
- demo.launch()
 
 
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
+