Spaces:
Sleeping
Sleeping
meta-llama/llama-2-7b-hf
Browse files
app.py
CHANGED
|
@@ -1,41 +1,12 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import torch # <-- ADD THIS LINE
|
| 4 |
|
| 5 |
-
# Load GPT-2 with optimized parameters
|
| 6 |
model = pipeline(
|
| 7 |
"text-generation",
|
| 8 |
-
model="
|
| 9 |
-
|
| 10 |
-
temperature=0.7,
|
| 11 |
-
early_stopping=True,
|
| 12 |
-
torch_dtype=torch.float32 # CPU compatibility
|
| 13 |
)
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
prompt = f"{
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
result = model(prompt, max_time=10)[0]["generated_text"]
|
| 20 |
-
return result.strip()
|
| 21 |
-
except Exception as e:
|
| 22 |
-
return f"Error: {str(e)}"
|
| 23 |
-
|
| 24 |
-
# Create Gradio interface
|
| 25 |
-
demo = gr.Interface(
|
| 26 |
-
fn=chat_with_gpt2,
|
| 27 |
-
inputs="text",
|
| 28 |
-
outputs="text",
|
| 29 |
-
title="GPT-2 Chat Interface",
|
| 30 |
-
description="Type any message to chat with GPT-2.",
|
| 31 |
-
flagging_mode="never"
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# Launch the app
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
demo.launch(
|
| 37 |
-
server_name="0.0.0.0",
|
| 38 |
-
server_port=7860,
|
| 39 |
-
debug=True,
|
| 40 |
-
prevent_thread_lock=True
|
| 41 |
-
)
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
|
|
|
| 2 |
|
|
|
|
| 3 |
model = pipeline(
|
| 4 |
"text-generation",
|
| 5 |
+
model="meta-llama/llama-2-7b-hf",
|
| 6 |
+
torch_dtype=torch.float16 # Reduce memory usage
|
|
|
|
|
|
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
+
def generate_test_cases(requirement):
|
| 10 |
+
prompt = f"Generate test cases for '{requirement}' in JSON format. Output only the array."
|
| 11 |
+
result = model(prompt, max_length=300)[0]["generated_text"]
|
| 12 |
+
return result.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|