research14 commited on
Commit
74d11d9
·
1 Parent(s): 57539e8

test interface

Browse files
Files changed (2) hide show
  1. __pycache__/run_llm.cpython-311.pyc +0 -0
  2. app.py +16 -21
__pycache__/run_llm.cpython-311.pyc ADDED
Binary file (10.5 kB). View file
 
app.py CHANGED
@@ -1,30 +1,25 @@
1
  import gradio as gr
2
- import os
3
- import json
4
- import openai
5
  import torch
6
- from transformers import AutoTokenizer, AutoModelForCausalLM
7
- from run_llm import model_mapping, fastchat # Import the necessary function from run_llm.py
8
 
9
- # Set your OpenAI API key
10
- openai.api_key = "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"
 
 
11
 
12
- def generate_text(input_text, model, prompt_type):
13
- # Use the fastchat function from run_llm.py
14
- outputs = fastchat(input_text, model, prompt_type)
15
- return outputs
 
16
 
 
17
  iface = gr.Interface(
18
- fn=generate_text,
19
- inputs=[
20
- gr.Textbox("input_text", label="Input Text"),
21
- gr.Dropdown(
22
- list(model_mapping.keys()),
23
- label="Model"
24
- ),
25
- gr.Radio([1, 2], label="Prompt Type"),
26
- ],
27
- outputs=gr.Textbox("output_text", label="Generated Text")
28
  )
29
 
 
30
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
 
 
3
  import torch
 
 
4
 
5
+ # Load pre-trained GPT-3.5 model and tokenizer (you can replace this with your model)
6
+ model_name = "EleutherAI/gpt-neo-2.7B"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
+ def generate_text(input_text, max_length=50):
11
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
12
+ output = model.generate(input_ids, max_length=max_length, num_return_sequences=1)
13
+ generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
14
+ return generated_text
15
 
16
+ # Create a Gradio interface
17
  iface = gr.Interface(
18
+ fn=generate_text, # Your text generation function
19
+ inputs=gr.Textbox(text="Enter text here..."), # Text input field
20
+ outputs=gr.Textbox(), # Display generated text
21
+ live=True # Real-time updates
 
 
 
 
 
 
22
  )
23
 
24
+ # Launch the interface
25
  iface.launch()