willbraun commited on
Commit
9763456
1 Parent(s): a24fcca

starting to play with gpt-2

Browse files
Files changed (3) hide show
  1. .gitignore +0 -0
  2. app.py +26 -2
  3. requirements.txt +2 -0
.gitignore ADDED
File without changes
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from langchain_huggingface import HuggingFacePipeline
3
+
4
+ llm = HuggingFacePipeline.from_model_id(
5
+ model_id="openai-community/gpt2",
6
+ task="text-generation",
7
+ pipeline_kwargs={
8
+ "max_new_tokens": 5,
9
+ "temperature": 1,
10
+ },
11
+ )
12
 
13
  def greet(name):
14
  return "Hello " + name + "!!"
15
 
16
+ # Define a function to generate responses
17
+ def chat_with_model(user_input):
18
+ print(llm.invoke(user_input))
19
+ return llm.invoke(user_input)
20
+
21
+ # Create a Gradio interface
22
+ demo = gr.Interface(
23
+ fn=chat_with_model,
24
+ inputs="text",
25
+ outputs="text",
26
+ title="Chat with GPT-2",
27
+ description="Enter a prompt and get a response from GPT-2."
28
+ )
29
+
30
+ # Launch the interface
31
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ langchain-huggingface