ivmpfa commited on
Commit
5c4737d
·
verified ·
1 Parent(s): 2d839f4

meta-llama/llama-2-7b-hf

Browse files
Files changed (1) hide show
  1. app.py +6 -35
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="gpt2",
9
- max_length=200,
10
- temperature=0.7,
11
- early_stopping=True,
12
- torch_dtype=torch.float32 # CPU compatibility
13
  )
14
 
15
- def chat_with_gpt2(user_input):
16
- prompt = f"{user_input}"
17
- try:
18
- with torch.no_grad():
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()