Spaces:
Runtime error
Runtime error
File size: 2,051 Bytes
756d547 a8061c1 90a2343 a8061c1 cce5c46 a8061c1 756d547 90a2343 dacdb7e 90a2343 a8061c1 756d547 a8061c1 756d547 a8061c1 756d547 90a2343 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# import gradio as gr
# from transformers import pipeline
# # Load the pre-trained model
# generator = pipeline("question-answering", model="EleutherAI/gpt-neo-2.7B")
# # Define Gradio interface
# def generate_response(prompt):
# # Generate response based on the prompt
# response = generator(prompt, max_length=50, do_sample=True, temperature=0.9)
# return response[0]['generated_text']
# # Create Gradio interface
# iface = gr.Interface(
# fn=generate_response,
# inputs="text",
# outputs="text",
# title="OpenAI Text Generation Model",
# description="Enter a prompt and get a generated text response.",
# )
# # Deploy the Gradio interface
# iface.launch(share=True)
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "microsoft/phi-2"
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
def generate_answer(question):
inputs = tokenizer.encode("Question: " + question, return_tensors="pt")
outputs = model.generate(inputs, max_length=2000, num_return_sequences=1, do_sample=True)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
return answer
iface = gr.Interface(
fn=generate_answer,
inputs="text",
outputs="text",
title="Open-Domain Question Answering",
description="Enter your question to get an answer.",
)
iface.launch(share=True) # Deploy the interface
# from transformers import AutoModelForCausalLM, AutoTokenizer
# model_name = "abacusai/Smaug-72B-v0.1"
# model = AutoModelForCausalLM.from_pretrained(model_name)
# tokenizer = AutoTokenizer.from_pretrained(model_name)
# def generate_answer(question):
# inputs = tokenizer.encode("Question: " + question, return_tensors="pt")
# outputs = model.generate(inputs, max_length=100, num_return_sequences=1, early_stopping=True, do_sample=True)
# answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
# return answer
|